Hide the right element of the NavigationBar button on iPhone

I want to hide rightNavigationBarItem when my ViewController loads. How is this possible? I tried this code but it does not work.

self.navigationItem.rightBarButtonItem = nil; 
+6
source share
7 answers

In Xcode 4. using these functions will not work;

 self.navigationItem.leftBarButtonItem.enabled=NO; self.navigationItem.leftBarButtonItem=nil; self.navigationController.navigationBar.backItem.hidesBackButton=YES; [self.navigationItem.leftBarButtonItem release]; 

I am really wondering why you are specifying rightBarButtonItem? When you move, its leftBarButtonItem element changes.

What works,

1) self.title =@ ""; resetting the title of the screen when the navigation controller pushes a detailed view onto the stack; no reverse button is created.

2) replacing leftBarButtonItem with something else, changing the button, but not solving your problem.

3) Alternative. Hide the navigation bar; [self.navigationController setNavigationBarHidden:YES animated:YES];

+6
source

Hi, he does not hide, but turns it off

  self.navigationItem.rightBarButtonItem.enabled = NO; 
+5
source

put this function in all classes -

  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.navigationItem.rightBarButtonItem = nil; } return self; } 
+2
source

First of all, you should not subclass UITabBarController, as it is quite clearly indicated in the documentation . He mentioned very early in the review.

Assuming one of the tabs points to a UINavigationController . You should really access the view controller directly and do something like viewController.navigationItem.rightBarButtonItem = nil; .

+2
source

You must set rightBarButtonItem to nil before pushing the controller onto the navigation stack.

+1
source

Directly hiding the right button does not work. Here's a trick for this.

Note. This solution only works for iOS 7.x.

 //To Hide self.navigationItem.rightBarButtonItem.enabled = NO; self.navigationItem.rightBarButtonItem.title = @""; //To Show self.navigationItem.rightBarButtonItem.enabled = YES; self.navigationItem.rightBarButtonItem.title = @"DONE"; 
+1
source

I think it is best to use this line code example:

 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:nil style:UIBarButtonItemStylePlain target:nil action:nil]; 
0
source

Source: https://habr.com/ru/post/888391/


All Articles