UIBarButtonItem is not displayed

My application layout is as follows:

rootViewController is a tabViewController with 3 tabs, each of which has a UINavigationController as its rootViewController. In one of these tabs, I click on the cell selection on another tabController, which now has two tabs. What I'm trying to do is set rightBarButtonItem for each of these two viewControllers tab elements ... in the viewDidLoad method of both of them I do:

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

however, it does absolutely nothing! I thought from the Apple docs that you can set navigationItem rightBarButtonItem from anywhere in the hierarchy of your navigation controller, but it doesn't seem to be that way. Any idea what - if anything - am I doing wrong?

+7
ios uinavigationitem uinavigationcontroller uibarbuttonitem
source share
1 answer

The solution to this is that instead of simply setting the BarButtonItem right to self.navigationItem, we need to set it to the parent tabBarController as follows:

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

All Articles