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?
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With