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?
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?
Show:
Hide:
SWIFT 2.2
In swift 2.2 self.navigationItem does not work. Instead create an outlet of the NavigationItem (I named it below "nav") and use it.
Also the following suggestion did not work for me using Xcode 7.3 and swift 2.2
So I used the idea of @Matt J above as follows (I have 2 items on the left):
Create outlets for the items in the navigation bar and variables to store them
Save the items in viewDidLoad()
To HIDE set them to nil
To SHOW them
Credit has to go to learner for this answer which the answer is from this question:
hide and show left navigation bar button on demand in iOS-7
This is the answer, which is far more simple.
Then you just reference the method where you require it like within an
(IBAction)
like so:I tried all other methods and none worked, even referencing my button as a
@property (...) UIBarButtonItem....
and nothing worked until I found this.Here's Matt's solution updated for Storyboards & ARC. Remember, IBOutlets are __weak by default, so you need to change that to strong for it not to be released too early.
Set the the title to empty first and after swlwction just set again.
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.
Personally, in my apps I make my nav buttons into @properties, so that I can trash & recreate them at will, so something like: