How can I hide a UIBarButtonItem?

The Crazy Chimp picture The Crazy Chimp · Oct 21, 2011 · Viewed 20.4k times · Source

I have created a simple UI in IB, this consists of a UINavigationBar and a UIBarButtonItem that I dragged and dropped on the right hand side.

I am trying to set this button to be hidden a certain times but I am having some problems.

So far I have tried using:

self.NavigationItem.rightBarButton = nil;

...which didn't work for me. I have also tried creating and IBOutlet and linking it to the button however I'm having problems with this too. I think it should be pretty simple and maybe I'm over-complicating it, but at this point I'm pretty stumped!

Please can someone help me out?

Answer

chown picture chown · Oct 21, 2011

UINavigationItem doesnt have a rightBarButton property. Try rightBarButtonItem instead (or [self.navigationItem setRightBarButtonItem:nil animated:NO];):

self.navigationController.navigationItem.rightBarButtonItem = nil;
// Or
self.navigationItem.rightBarButtonItem = nil;
// Or
[self.navigationItem setRightBarButtonItem:nil animated:NO];