Search code examples
iosuinavigationcontrolleruinavigationbaruinavigationitem

Disable other bar button items when one is being touched: Navigation bar


I have a navigation controller, in its navigation bar i've 2 right bar button items, I want to disable one right bar button when the other is being clicked/tapped. How to achieve this??

Thanks in advance.


Solution

  • Unfortunately UIBarButtonItems only have one callback and that's the equivalent of UIButton's UIControlEventTouchUpInside.

    If you want to do something when the user presses and releases a button (disable/re-enable other buttons) you might have to get your hands dirty with some custom UIBarButtonItems that have UIButton's as customView and do some careful event handling to know when to enable/disable each.

    On a personal note: pressing more than one bar button at the same time is not very common and shouldn't present a problem, whatever implementation you may have.