How I hide the rightBarButtonItem of a navigation controller when I want to navigate from tab-bar instead of Navigation Controller.
Asked
Active
Viewed 2,697 times
0
-
1Duplicate of http://stackoverflow.com/questions/825066/how-to-disable-the-edit-button-that-appears-in-the-more-section-of-a-uitabbarcon – petert Mar 22 '13 at 11:22
-
this post is related to enable the button, not to hide – Mar 22 '13 at 11:30
-
Please add some code in your question. – Petar Mar 22 '13 at 11:31
-
if(self.parentViewController == self.navigationController ) { UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(Done)]; self.navigationItem.rightBarButtonItem = rightButton; self.navigationItem.hidesBackButton = YES; } if(self.parentViewController == self.tabBarController ){ self.navigationItem.rightBarButtonItem = nil; } – Mar 22 '13 at 11:34
-
The top answer shows setting the button to nil, so it disables it. – petert Mar 22 '13 at 11:35
2 Answers
2
To Hide the right button:
self.navigationItem.rightBarButtonItem = nil;
And to show it:
If you setup the right button in your view controller by assigning it to self.editButtonItem then simply assign it again in order to show it:
self.navigationItem.rightBarButtonItem = self.editButtonItem;

Irfan
- 4,301
- 6
- 29
- 46
-
How hide one of two rightBarButtonItem ? `self.navigationItem.rightBarButtonItems[index] = nil ;` don't work. – zhaoyou Nov 17 '16 at 11:23
0
Just write this line in viewDidLoad or viewWillAppear of the class in which you want to hide the right bar button
self.navigationItem.rightBarButtonItem = nil;

Shah Paneri
- 729
- 7
- 28
-
if(self.parentViewController == self.navigationController ) { UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(Done)]; self.navigationItem.rightBarButtonItem = rightButton; self.navigationItem.hidesBackButton = YES; } if(self.parentViewController == self.tabBarController ){ self.navigationItem.rightBarButtonItem = nil; } – Mar 22 '13 at 11:27
-
First you have navigation controller and then you have tabbar controller. Right? – Shah Paneri Mar 22 '13 at 11:29
-
yes I have two way navigation in my project....I want hide the done button when user tab on tabbar...mean when tabbar open the navigationbar will be plain having no button on it – Mar 22 '13 at 11:33
-
pls refer this question to set navigation controller and then tabbar.It'll help you. http://stackoverflow.com/questions/15377764/how-to-go-to-home-page-in-ios-app/15380682#15380682 – Shah Paneri Mar 22 '13 at 11:44