I have added a BarButton
item to the left of the nav.bar
through Interface Builder and in the code I want this only to show in my table view's edit mode. But I didn't find any hidden property to set the leftBarButtonItem
(like: self.navigationItem.leftBarButtonItem.hidden = YES
).
I can only set enabled
property. Anybody know how to control the hide and show property of the leftBarButtonItem
, please help.
To hide/disable
To show/enable
This solution work for me
There's nothing in the documentation to suggest bar items have a hidden property.
Why not set
when the user isn't editing, then set
when the user is editing? This requires either re-creating the button each time or storing it for the duration of the view's lifecycle. Neither is terribly painful, but no, not nearly as easy as a .hidden property.
I just created my own "hide" function show below:
You can just call it like:
or
You can use
The key is making sure that you have a strong reference to the button item before nilling
leftBarButtonItem
.I'm pretty sure the only way to "hide" it is to nil it out.
Though it's not a perfect answer to your question, since that basically gets rid of your button instead of hiding it. You'll either have to recreate it or keep your original button around and simply set the leftBarButtonItem back to your UIBarButtonItem.