I currently have a custom UINavigationController written in Objective-C that has a rootViewController which implements
- (UINavigationItem *)navigationItem
The implementation looks something like this:
- (UINavigationItem *)navigationItem {
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Map Search"];
item.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStylePlain target:nil action:nil];
UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_menu"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonPressed:)];
item.leftBarButtonItem = leftBarButtonItem;
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Other Button" style:UIBarButtonItemStylePlain target:self action:@selector(otherButtonPressed:)];
item.rightBarButtonItem = rightBarButtonItem;
return item;
}
This is working correctly and displaying my buttons in the navigation bar of my rootViewController as expected. However, when I attempt to hide the bar button items, nothing happens. I've tried setting the buttons to nil and creating UIBarButtonItem strong properties to keep references to my buttons to return to previous state later, e.g.
self.navigationController.navigationItem.rightBarButtonItem = nil;
...
self.navigationController.navigationItem.rightBarButtonItem = _strongPropertyUIBarButtonReference;
I've also tried referencing the buttons via
self.navigationItem.rightBarButtonItem
I've tried hiding these buttons with the alpha property. I've tried creating a method in my custom UINavigationController class that sets the bar button item references to nil. All to no avail. Any help would be really appreciated.