How do I add a button to my navigationController's right side after pushing another view controller

Posted by bobobobo on Stack Overflow See other posts from Stack Overflow or by bobobobo
Published on 2009-11-24T04:11:54Z Indexed on 2010/04/06 17:03 UTC
Read the original article Hit count: 517

So, immediately after pushing a view controller to my tableView,

// Override to support row selection in the table view.
- (void)tableView:(UITableView *)tableView
        didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  // Navigation logic may go here --
  //   for example, create and push another view controller.
  AnotherViewController *anotherViewController = 
      [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
  [self.navigationController pushViewController:anotherViewController animated:YES];

Ok, so that makes another view slide on, and you can go back to the previous view ("pop" the current view) by clicking the button that automatically appears in the top left corner of the navigation bar now.

Ok, so SAY I want to populate the RIGHT SIDE of the navigation bar with a DONE button, like in the "Notes" app that comes with the iPhone. How would I do that?

I tried code like this:

  UIBarButtonItem * doneButton =
  [[UIBarButtonItem alloc]
   initWithBarButtonSystemItem:UIBarButtonSystemItemDone
   target:self
   action:@selector( doneFunc ) ];

  self.navigationController.navigationItem.rightBarButtonItem = doneButton ; // not it..

  [doneButton release] ;

doneFunc is defined, and everything, just the button never appears on the right side..

© Stack Overflow or respective owner

Related posts about iphone-sdk

Related posts about uinavigationcontroller