Hide the rightNavigationBar button item in iPhone

29,059

Solution 1

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];

Solution 2

Hi it does not hide but make it disable

 self.navigationItem.rightBarButtonItem.enabled = NO;

Solution 3

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;
}

Solution 4

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;.

Solution 5

You should set rightBarButtonItem to nil before you insert your controller into a navigation stack.

Share:
29,059
Rani
Author by

Rani

Updated on July 28, 2022

Comments

  • Rani
    Rani almost 2 years

    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;
    
  • Henrik Erlandsson
    Henrik Erlandsson almost 13 years
    @eSpecialized: This is incorrect. Also, he did ask about the right bar button and your assuming he doesn't know which button he wants to hide is...strange.
  • Bill Thompson
    Bill Thompson about 11 years
    @HenrikErlandsson - because when a view controller loads. There is no button left or right, unless its part of a navigation stack. The question suggests that he is having issues with the Left button. Perhaps an edit to the original question should be inquired. I read the question as a Navigation Stack push, which would mean left button.