I have added a BarButton
item to the left of the nav.bar
through Interface Builder and in the code I want this only to show in my table view\'s edi
func showOrHideButton() {
isEnabled ? showButton() : hideButton()
}
func showButton() {
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(action))
}
func hideButton() {
navigationItem.leftBarButtonItem = nil
}
I have a easy function to make this. I have a navigation like this. It comes form Interface Builder, it has a background image.
@IBOutlet weak var memberBtn: UIBarButtonItem!
you can hide/show it by:
func hideMemberBtn() {
memberBtn.isEnabled = false
memberBtn.tintColor = UIColor.clear
}
func showMemberBtn() {
memberBtn.isEnabled = true
memberBtn.tintColor = UIColor.white
}
It's easy but it work for me. You can change tintColor as you needed. Hope for help :]
There's nothing in the documentation to suggest bar items have a hidden property.
Why not set
self.navigationItem.leftBarButtonItem = nil;
when the user isn't editing, then set
self.navigationItem.leftBarButtonItem = whateverBarButtonItem;
when the user is editing? This requires either re-creating the button each time or storing it for the duration of the view's lifecycle. Neither is terribly painful, but no, not nearly as easy as a .hidden property.
This solution work for me
UIView *myView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 300, 30)];
UIBarButtonItem *btnL = [[UIBarButtonItem alloc]initWithCustomView:myView];
self.navigationItem.leftBarButtonItem = btnL;
To hide/disable
[self.navigationItem.leftBarButtonItem setEnabled:FALSE];
To show/enable
[self.navigationItem.leftBarButtonItem setEnabled:TRUE];