Domanda

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;
È stato utile?

Soluzione

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

Altri suggerimenti

Hi it does not hide but make it disable

 self.navigationItem.rightBarButtonItem.enabled = NO;

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

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

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

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

I think best way is by this sample line code:

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:nil style:UIBarButtonItemStylePlain target:nil action:nil];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top