[self setButtonItem:nil];
Not hides my bar button item.
And how to show it again?
[self setButtonItem:nil];
Not hides my bar button item.
And how to show it again?
another option could be disable and set it color to clearColor, and then enable and set it to the original color again, like this:
self.rightButton.tintColor = [UIColor clearColor];
self.rightButton.enabled = NO;
and later:
self.rightButton.tintColor = [UIColor blackColor];
self.rightButton.enabled = YES;
Unlike UIViews, there is no "hidden" property you can use here. You'll need to remove your bar button item from your navigation bar or toolbar to hide it and re-add it to show it again.
Using something like this (assuming this is part of the navigation bar):
self.navigationItem.rightBarButtonItem = nil;
Unless it's the "back" button, in which case there's a specific API call you can use.
In Swift 4, If you have only one bar button item in the right side you can use this one,
self.navigationItem.rightBarButtonItem = nil; //To Hide
self.navigationItem.rightBarButtonItem = barButtonItem //To show
Suppose if you have multiple bar button in the right side, for example suppose you have two bar button items(search button and filter button) in the right side of your navigation item. Now the right bar button items are
self.navigationItem.rightBarButtonItems = [searchItem,filterItem]
and you have to hide only search button, you can use like,
self.navigationItem.rightBarButtonItems = [filterItem]
Now what happening is, you can completely hide the search button from the navigation item and the filter item comes in the place of search item
Then if you want to show the hided bar button,
self.navigationItem.rightBarButtonItems = [searchItem, filterItem]