How to Hide the UInavigationBar Rightbarbutton item?
I added the info button to the navigation bar using below 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 at some part of the code based on some conditions. But i didn't find any hi开发者_运维知识库de property for right bar button item in the navigation bar?
For making hidden, try with assigning nil
to your rightBarButtonItem
like below.
self.navigationItem.rightBarButtonItem = nil ;
Best option is to use buttonItem.enabled = NO
to indicate the functionality isn't available at the moment. That should, in most cases, be the right behavior.
However if you intend to make it disappear, the best way would be to store a reference to the bar button. Set the rightBarButtonItem to nil when you want it to disappear and set it to the stored reference when you want it to be displayed.
If you have multiple UIBarButtonItems and you just want to remove one, you can do this:
NSMutableArray *barButtonItems = [self.toobbar.items mutableCopy];
[barButtonItems removeObject:self.buttonToRemove];
[self.toolbar setItems:[barButtonItems copy] animated:NO];
If you just want to 'hide' it visually:
Swift 3:
self.navigationItem.rightBarButtonItem?.tintColor = UIColor.clear
self.navigationItem.rightBarButtonItem?.isEnabled = false
精彩评论