I’m having problems displaying the rightBarButtonItem of the Navigation Bar – I’m attempting to create it programmatically in the Application Delegate, where my UINavigationController is set up.
Code is as follows:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
RSCListViewController *list = [[RSCListViewController alloc] initWithStyle:UITableViewStylePlain];
self.navController = [[UINavigationController alloc] initWithRootViewController:list];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"+"
style:UIBarButtonItemStylePlain
target:list
action:@selector(addPressed:)];
self.navController.navigationItem.rightBarButtonItem = barButton;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[DatabaseManager openDatabase];
return YES;
}
Running the application, no button item appears on the navigation bar.
I’m not sure whether I have missed something obvious – my attempts to rectify the problem using related Stack Overflow threads haven’t yielded any success.
Any help appreciated.
You need to attach your bar button item to your custom view controller, not to the navigation controller. From Updating the Navigation Bar:
Therefore, replace:
with: