Can't add a rightBarButtonItem to a NavigationBar
I'm trying to build an app (for practice) that uses CoreData and different view controllers.
I'm currently blocked, because I can't manage to add a rightBarButtonItem
to a navigationBar.
Here is the code I'm using (in the AppDelegate
, application:didFinishLaunchingWithOptions:).
PersoneTableViewController *ptvc = [[PersoneTableViewController alloc] initWithStyle:UITableViewStylePlain];
ptvc.managedObjectContext = self.managedObjectContext;
ptvc.title = @"Persone";
UINavigationController *navCon = [[UINavigationController alloc] init];
[navCon pushViewController:ptvc animated:NO];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(addPressed)];
navCon.navigationItem.rightBarButtonItem = barButtonItem;
[barButtonItem release];
self.windo开发者_运维百科w.rootViewController = navCon;
[navCon release];
[self.window makeKeyAndVisible];
return YES;
But the rightBarButtonItem is not showed if I run the app in the simulator.
A UInavigationController
will use the navigationItem
from it's topmost view controller (and second to topmost for the back button). Not it's own navigationItem
as in your example.
精彩评论