1

我正在尝试在 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];
4

3 回答 3

2
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(favouriteButtonClicked:)]; 
videoController.navigationItem.rightBarButtonItem = button; 
[button release];
于 2011-07-13T12:25:05.837 回答
0

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

于 2012-02-19T03:20:50.643 回答
-2

Try this..it will work

[[[UIApplication sharedApplication] keyWindow] addSubview:favButton];
于 2013-02-11T14:40:59.153 回答