I added my left navigation bar button using the storyboard. but I want it to hide when I first load the screen. And then in response to something else, I want it to show. The navigation bar has a method for hiding the back button. But there is no method for hiding/showing the left button. Is there a simple way for doing this? Or do I have to use two methods: the hiding method creates an empty button and the showing method creates the correct button? The button in question is just the Add
template that iOS provides (which makes it easy to just use the one in the storyboard than to create my own).
Asked
Active
Viewed 1.4k times
8

learner
- 11,490
- 26
- 97
- 169
3 Answers
30
Here is how I solved it
-(void) hideAndDisableRightNavigationItem
{
[self.navigationItem.rightBarButtonItem setTintColor:[UIColor clearColor]];
[self.navigationItem.rightBarButtonItem setEnabled:NO];
}
-(void) showAndEnableRightNavigationItem
{
[self.navigationItem.rightBarButtonItem setTintColor:[UIColor blackColor]];
[self.navigationItem.rightBarButtonItem setEnabled:YES];
}

learner
- 11,490
- 26
- 97
- 169
-
1That is sexy. Best solution on stack. – App Dev Guy Dec 03 '14 at 02:48
-
I referenced this in my answer on a similar question. Hope you don't mind. http://stackoverflow.com/questions/5588767/how-do-i-hide-show-the-right-button-in-the-navigation-bar/27262875#27262875 – App Dev Guy Dec 03 '14 at 02:59
-
What if I have more than one navigation bar button items? left or right where ever.. – Mathi Arasan Feb 04 '16 at 15:37
8
Swift version of @learner answer
func hideAndDisableRightNavigationItem (){
self.navigationItem.rightBarButtonItem?.enabled = false
self.navigationItem.rightBarButtonItem?.tintColor = UIColor.clearColor()
}
func showAndEnableRightNavigationItem(){
self.navigationItem.rightBarButtonItem?.enabled = true
self.navigationItem.rightBarButtonItem?.tintColor = UIColor. blackColor()
}

LHIOUI
- 3,287
- 2
- 24
- 37
-2
Here is what I did. On the initial screen I wanted to hide the navigation bar:
self.navigationController.navigationBarHidden = YES;
On the second screen I wanted to show the navigation bar so I set:
self.navigationController.navigationBarHidden = NO;

dland
- 4,319
- 6
- 36
- 60

Nex Mishra
- 774
- 7
- 13