Reputation: 3453
I want to hide the rightNavigationBarItem when my ViewController loads. How is it possible? I have tried this code but it is not working.
self.navigationItem.rightBarButtonItem = nil;
Upvotes: 6
Views: 29122
Reputation: 331
I think best way is by this sample line code:
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:nil style:UIBarButtonItemStylePlain target:nil action:nil];
Upvotes: 0
Reputation: 3684
Directly hide right button is not working Below is trick for do it.
Note: This solution work for iOS 7.x only.
//To Hide
self.navigationItem.rightBarButtonItem.enabled = NO;
self.navigationItem.rightBarButtonItem.title = @"";
//To Show
self.navigationItem.rightBarButtonItem.enabled = YES;
self.navigationItem.rightBarButtonItem.title = @"DONE";
Upvotes: 1
Reputation: 198
In Xcode 4. using these won't work;
self.navigationItem.leftBarButtonItem.enabled=NO;
self.navigationItem.leftBarButtonItem=nil;
self.navigationController.navigationBar.backItem.hidesBackButton=YES;
[self.navigationItem.leftBarButtonItem release];
I'm actually interested why you mention rightBarButtonItem? When you navigate, its the leftBarButtonItem that changes.
What Does Work;
1) self.title =@"";
nulling the title of the screen, when the navigation controller pushes a detail view onto the stack, no back button is created.
2) replacing the leftBarButtonItem
with something else changes the button, but doesn't solve your problem.
3) An alternative. Hide the navigation bar; [self.navigationController setNavigationBarHidden:YES animated:YES];
Upvotes: 6
Reputation: 44633
First of all you shouldn't be subclassing UITabBarController as stated quite clearly in the documentation. It's mentioned very early in the overview.
Assuming that one of tabs points to a UINavigationController
. You should really access the view controller directly and do something like viewController.navigationItem.rightBarButtonItem = nil;
.
Upvotes: 2
Reputation: 1977
put this function in all the classes -
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.navigationItem.rightBarButtonItem = nil;
} return self;
}
Upvotes: 2
Reputation: 3043
Hi it does not hide but make it disable
self.navigationItem.rightBarButtonItem.enabled = NO;
Upvotes: 5
Reputation: 2461
You should set rightBarButtonItem to nil before you insert your controller into a navigation stack.
Upvotes: 1