开发者

iPhone: Add button on MPMoviePlayerViewController's navigation bar

I am trying to add button on MPMoviePlayerViewController's navigationcontroller.view. I have wrote following so far. It doesn't give any error but button isn't appearing on view! Could anyone please tell me what am I doing wrong? Thanks.

        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:UIControlEventTouchUpIn开发者_运维技巧side];
    [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");
}

Also try adding using following code but no luck!

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


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


If you use presentModalViewController, you can not see the button you add. You have to [self.navigationController pushViewController:moviePlayer animated:YES] to see it.


Try this..it will work

[[[UIApplication sharedApplication] keyWindow] addSubview:favButton];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜