Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I hide/show the right button in the Navigation Bar

I need to hide the right button in the Navigation Bar, then unhide it after the user selects some options.

Unfortunately, the following doesn't work:

NO GOOD: self.navigationItem.rightBarButtonItem.hidden = YES;  // FOO CODE 

Is there a way?

like image 955
Lauren Quantrell Avatar asked Apr 07 '11 23:04

Lauren Quantrell


People also ask

How do I hide navigation bar on Iphone?

You can find the Website View menu in what's called the Smart Search field at the top of the Safari interface. Launch the app and navigate to a website, then tap the "aA" icon in the upper left corner of the screen. Simply select Hide Toolbar from the dropdown menu, and the toolbar will shrink to show just the URL.


1 Answers

Hide the button by setting the reference to nil, however if you want to restore it later, you'll need to hang onto a copy of it so you can reassign it.

UIBarButtonItem *oldButton = self.navigationItem.rightBarButtonItem; [oldButton retain]; self.navigationItem.rightBarButtonItem = nil;  //... later self.navigationItem.rightBarButtonItem = oldButton; [oldButton release]; 

Personally, in my apps I make my nav buttons into @properties, so that I can trash & recreate them at will, so something like:

//mycontroller.h UIBarButtonItem *rightNavButton; @property (nonatomic, retain) UIBarButtonItem *rightNavButton;  //mycontroller.m @synthesize rightNavButton; - (UIBarButtonItem *)rightNavButton {     if (!rightNavButton) {         rightNavButton = [[UIBarButtonItem alloc] init];         //configure the button here     }     return rightNavButton; }  //later, in your code to show/hide the button: self.navigationItem.rightBarButtonItem = self.rightNavButton; 
like image 138
Matt J Avatar answered Sep 22 '22 02:09

Matt J