Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBarButtonItem not appearing

My app layout is as follows -

the rootViewController is a tabViewController with 3 tabs each having a UINavigationController as their rootViewController. Within one of these tabs I am pushing upon cell selection to another tabController which now has two tabs. What I am trying to do is set the rightBarButtonItem on each of these two tab's viewControllers... in the viewDidLoad method of both of these I am doing:

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(selectionChanged:)];

however this is doing absolutely nothing! I thought from the apple documentations that you could set the navigationItem's rightBarButtonItem from anywhere within your navigation controllers view hierarchy but that doesn't seem to be the case here. Any idea what - if anything - I am doing wrong?

like image 536
simonthumper Avatar asked Jul 21 '13 14:07

simonthumper


1 Answers

The solution to this is to instead of simply setting the rightBarButtonItem on self.navigationItem we need to set it on the parent tabBarController like so :

self.tabBarController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(selectionChanged:)];
like image 197
simonthumper Avatar answered Nov 07 '22 03:11

simonthumper