Recently I am facing the same issue and I solved it (thanks to Erik B., your answer inspired me! unfortunately i can't vote your answer yet)
I think my right bar button can't vanish because I called it in viewWillAppear
function, and at that function, self
isn't referred to current UIViewController
.
This worked for me, instead of setting the button in viewWillAppear
, I set it in navigationController:willShowViewController:animated:
function at previous UIViewController
.
For example, I call SecondViewController
from FirstViewController
and I want to hide right bar button in SecondViewController
, put this in FirstViewController.m
:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if ([viewController isKindOfClass:[SecondViewController class]]) {
[viewController.navigationItem setRightBarButtonItem:nil];
}
}