Hide the rightNavigationBar button item in iPhone

Rani picture Rani · May 18, 2011 · Viewed 29k times · Source

I want to hide the rightNavigationBarItem when my ViewController loads. How is it possible? I have tried this code but it is not working.

self.navigationItem.rightBarButtonItem = nil;

Answer

Bill Thompson picture Bill Thompson · May 18, 2011

In Xcode 4. using these won't work;

self.navigationItem.leftBarButtonItem.enabled=NO;
self.navigationItem.leftBarButtonItem=nil;
self.navigationController.navigationBar.backItem.hidesBackButton=YES;
[self.navigationItem.leftBarButtonItem release];

I'm actually interested why you mention rightBarButtonItem? When you navigate, its the leftBarButtonItem that changes.

What Does Work;

1) self.title =@""; nulling the title of the screen, when the navigation controller pushes a detail view onto the stack, no back button is created.

2) replacing the leftBarButtonItem with something else changes the button, but doesn't solve your problem.

3) An alternative. Hide the navigation bar; [self.navigationController setNavigationBarHidden:YES animated:YES];