tags:

views:

262

answers:

0

Hi, I can't figure out why when run the following code does not show the right bar button. Simple code, gets executed when I click a table cell in my main table view controller. Modal view shows with nav bar but no right button:

//Create blank view controller
UIViewController *modalViewController = [[[UIViewController alloc] initWithNibName:nil bundle:nil] autorelease];

//Create a new navigation controller with a right button to host the account view controller
UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithRootViewController:modalViewController];

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self.navigationController action:@selector(dismissModalViewControllerAnimated:)];


secondNavigationController.navigationItem.rightBarButtonItem = barButton;
[barButton release];

[[self navigationController] presentModalViewController:secondNavigationController animated:YES];
[secondNavigationController release];

INTERESTING NOTES: I have an existing table view controller/nib that I tried this with as well, same result, except that if I go into the .m for the controller and uncomment the self.navigationItem.rightBarButtonItem = self.editButtonItem; line in viewDidLoad, the Edit/Done button does display. Also, I seem to only see code to add nav bar buttons in the viewDidLoad methods. The code above is not located in that method but in the didSelectRowAtIndexPath: method.

thanks!