As the question says, I need to be able to change the contents of the UINavigationBar when different UIViewControllers are displayed by the UINavigationController. This is easily achievable for titles since the navigation controller just uses the view controller's title property. What I am struggling with is changing the left and right bar button items depending on the view controller.
The code that I would use to change them has already been addressed in multiple other questions and isn't really the issue, although for reference I will be using the following:
UIBarButtonItem *newItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemAdd target:self action:nil];
newItem.tintColor = [UIColor whiteColor];
self.navigationItem.rightBarButtonItem = newItem;
I think what I am looking for is a method which is called every time that a new UIViewController is shown by the navigation controller in order to set up the navigation controller layout. In the documentation of the UINavigationController is the following method:
// Called when the navigation controller shows a new top view controller via a push, pop or setting of the view controller stack.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
However, this method is seemingly not called at any point when I run the app. So, is there a method which is called when a new view controller is shown by the navigation controller? Or am I going completely wrong here and there is already an accepted way of having the navigation bar change with the view being displayed beneath it which I have so far missed?
UINavigationControllerDelegateprotocol, not theUINavigationControlleritself. Have you adopted the protocol and set thedelegate? - pbasdf