I created a toolbar in IB with several buttons. I would like to be able to hide/show one of the buttons depending on the state of the data in the main window.
UIBarButtonItem doesn’t have a hidden property, and any examples I’ve found so far for hiding them involve setting nav bar buttons to nil, which I don’t think I want to do here because I may need to show the button again (not to mention that, if I connect my button to an IBOutlet, if I set that to nil I’m not sure how I’d get it back).
Save your button in a strong outlet (let’s call it
myButton) and do this to add/remove it:Because it is stored in the outlet, you will keep a reference to it even when it isn’t on the toolbar.