How to disable UIBarButtonItem?
If your toolbar has an IBOutlet (and you've checked to make sure it's non-nil), try:
[ [ [ myToolBar items ] objectAtIndex: myBarButtonItemIndex ] setEnabled:(NO) ];
You can disable the left navigation button from inside an UIViewController like this, without using any IBOutlet:
self.navigationItem.leftBarButtonItem.enabled = NO;
To disable the right navigation button:
self.navigationItem.rightBarButtonItem.enabled = NO;
Swift3
self.navigationItem.rightBarButtonItem?.isEnabled = false
I used a different solution (Swift 4.2) for my rightBarButtonItems.
I had 3 buttons so used a for loop, then made an extension of UINavigationItem so I could use it throughout my app.
extension UINavigationItem {
func setRightBarButtonItems(isEnabled:Bool){
for button in self.rightBarButtonItems ?? [UIBarButtonItem()] {
button.isEnabled = isEnabled
}
}
Then i can call it from my TableViewController
navigationItem.setRightBarButtonItems(isEnabled: false)