I've build an app with around 12 view. In the top right of the NavigationBar there should be UIBarButton which has the exact same functionality for the whole app. It shows a custom button with a badge on it.
I pass the rightBarButtonItem down through TableViewControllers amd it works well. But the custom button disappears sometimes when i tap through the TabBar. Probably my solution is bad. I tried to set the custom button from the AppDelegate but i can't figure out how to reach rightBarButtonItem on every ViewController related to the TabBar.
I've tried something like this, but it always shows nil in the log.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
NSLog(@"item %@", self.tabController.selectedViewController.navigationItem.rightBarButtonItem);
NSLog(@"item %@", self.tabController.selectedViewController.navigationItem.rightBarButtonItems);
NSLog(@"item %@", self.tabController.selectedViewController.navigationController.navigationItem.rightBarButtonItems);
//self.tabController.selectedViewController.navigationItem.rightBarButtonItem =
[self switchTabBarImage:self.tabController.selectedIndex];
}
What is the best approach to realize somehting like a "global" rightBarButtonItem? And is the AppDelegate the right place for it?