iPhone:在MPMoviePlayerViewController的导航栏上添加按钮

时间:2011-07-13 10:15:12

标签: iphone mpmovieplayercontroller navigationcontroller

我正在尝试在MPMoviePlayerViewController的navigationcontroller.view上添加按钮。到目前为止我写了以下内容。它没有给出任何错误,但按钮没有出现在视图上!谁能告诉我我做错了什么?感谢。

        MPMoviePlayerViewController *videoController = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:filePath]] autorelease];
        UIButton *favButton = [UIButton buttonWithType:UIButtonTypeCustom];
        favButton.frame = CGRectMake(280, 25, 30, 30);
        [favButton addTarget:self action:@selector(favouriteButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [favButton setBackgroundImage:[UIImage imageNamed:@"unselected.png"] forState:UIControlStateNormal];
        [videoController.navigationController.view addSubview:favButton];
        [self presentMoviePlayerViewControllerAnimated:videoController];


- (void)favouriteButtonClicked:(id)sender
{
    NSLog(@"Inside favourite button clicked");
}

还尝试使用以下代码添加,但没有运气!

        UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(favouriteButtonClicked:)]; 
        videoController.navigationController.navigationItem.rightBarButtonItem=button; 
        [button release];

3 个答案:

答案 0 :(得分:2)

UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(favouriteButtonClicked:)]; 
videoController.navigationItem.rightBarButtonItem = button; 
[button release];

答案 1 :(得分:0)

如果使用 presentModalViewController ,则无法看到添加的按钮。你必须[self.navigationController pushViewController:moviePlayer animated:YES]才能看到它。

答案 2 :(得分:-2)

试试这个..它会起作用

[[[UIApplication sharedApplication] keyWindow] addSubview:favButton];
相关问题