How to hide Ubar NavigatorBar Rightbarbutton element?

I added an info button to the navigation bar using the following code:

UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; [infoButton addTarget:self action:@selector(showImage:) forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton]; 

Now I want to hide this button in some part of the code, based on some conditions. But I did not find any hide property for the right-click bar item in the navigation bar?

+4
source share
4 answers

To hide, try assigning nil your rightBarButtonItem , as shown below.

 self.navigationItem.rightBarButtonItem = nil ; 
+11
source

The best option is to use buttonItem.enabled = NO to indicate that functionality is currently unavailable. In most cases, this should be the correct behavior.

However, if you intend to make it disappear, the best way would be to save the link to the panel button. Set the rightBarButtonItem parameter to nil when you want it to disappear and set it to the saved link when you want it to appear.

+10
source

If you have multiple UIBarButtonItems and you just want to remove it, you can do this:

 NSMutableArray *barButtonItems = [self.toobbar.items mutableCopy]; [barButtonItems removeObject:self.buttonToRemove]; [self.toolbar setItems:[barButtonItems copy] animated:NO]; 
+1
source

If you just want to "hide" it visually:

Swift 3:

 self.navigationItem.rightBarButtonItem?.tintColor = UIColor.clear self.navigationItem.rightBarButtonItem?.isEnabled = false 
0
source

All Articles