I have a UIBarButtonItem that just doesn\'t want to get disabled. Short version: when I call
[myBarButtonItem setEnabled:NO];
Nothing happe
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
If your toolbar has an IBOutlet (and you've checked to make sure it's non-nil), try:
[ [ [ myToolBar items ] objectAtIndex: myBarButtonItemIndex ] setEnabled:(NO) ];
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)
In my case (Swift) I had 2 barButtonItems added as an array - so to disable them this did the trick
navigationItem.rightBarButtonItems?.first?.enabled = false
navigationItem.rightBarButtonItems?.last?.enabled = false