3
votes

I have a UINavigationController and am using the toolbar in one of my view controllers. I have several UIBarButtonItems. At various points, I disable certain buttons in the toolbar, using things like _btnEdit.enabled = NO.

This all works well except for one time where this happens when there is no user interaction. In that case, the button appears to be enabled (isn't grayed out), but doesn't accept touches. If I cover the bar with something (an action sheet from the bottom) or change the orientation of the device, it shows correctly.

I've tried self.navigationController.toolbar setNeedsDisplay] and [self.navigationController.toolbar drawRect:self.navigationController.toolbar.bounds] but neither have an any effect.

Any ideas on how to "refresh" this view? I know UIBarButtonItems don't inherit from UIView, which I feel like may be contributing to the issue.

1
Check if _btnEdit is nil when you are setting that.iDev
It's not nil. This is further shown by the button being disabled when the orientation is changed.Ned
Can you please put some more code to explain as to how you are disabling the buttons and in which situation it is not working correctly.Srikanth

1 Answers

3
votes

This is the intended behaviour. The setNeedsDisplay is a good reflex try, but you don't own the navigation bar and UIBarButtonItem doesn't inherit from UIView, so we need to think of them a little differently.
Here how you can achieve your goal :

UIBarButtonItem *bbi = self.navigationItem.rightBarButtonItem;
bbi.enabled = NO;
[self.navigationItem setRightBarButtonItem:bbi animated:YES];

NOTE : self is a UIViewController
I've just made a quick test with this and it's working.