I was trying to set a button so it appears on every view that has a navigation bar. Setting the appearance for all views is not a problem using the appearance proxy on the AppDelegate
[[UINavigationBar appearance] setTintColor:[UIColors grayColor]];
I was trying to subclass UINavigationController and then set that navigation controller on the storyboard. On the viewDidLoad method I’ve tried this:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"right"
style:UIBarButtonItemStyleBordered target:self action:nil];
But the button is not showing up.
If I do this:
self.navigationBar.topItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"right"
style:UIBarButtonItemStyleBordered target:self action:nil];
The button shows up but disappears once you go to the next screen.
I’m trying to do it so I don’t have to set up the right and left buttons on all viewDidLoad methods of each view controller. Is it possible to use a subclass of UINavigationController to set attributes of the navbar?
Apple tells us not to subclass UINavigationController:
That’s from the XCode version of the docs. The online version loosens up a bit, replacing that advice with:
How about creating a custom subclass of UIViewController with a modified viewDidLoad and base all of your custom VC’s on that?