1

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: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");
}

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];
Paresh Masani
  • 7,474
  • 12
  • 73
  • 139

3 Answers3

2
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(favouriteButtonClicked:)]; 
videoController.navigationItem.rightBarButtonItem = button; 
[button release];
beryllium
  • 29,669
  • 15
  • 106
  • 125
  • Note that navigationController property is referenced to UINavigationController instance that contains your other view controllers. So, this code adds button to nav bar of all your view controllers that referenced to your navigationController. I suggest that you wan't to add button to media player top bar (where situated Done and Resize standard buttons) - In this case one of solutions is to setup _controlStyle_ property = `MPMovieControlStyleNonecreate` and add overlay view with custom top bar and other controls. – beryllium Jul 13 '11 at 12:27
  • >> ...add button to media player top bar (where situated Done and Resize standard buttons)... << Exactly I want to do this! Could you please give me some tiny example for this? – Paresh Masani Jul 13 '11 at 13:49
  • 1
    your code didn't work either! I don't see any button still. Also I will need to add background image to that button. It doesn't seem to allow it! – Paresh Masani Jul 15 '11 at 15:59
0

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

Qiulang
  • 10,295
  • 11
  • 80
  • 129
-2

Try this..it will work

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