tags:

views:

1179

answers:

4

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.

+1  A: 

I'm pretty sure the only way to "hide" it is to nil it out.

self.navigationItem.leftBarButtonItem = nil;

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.

Neil Daniels
Thanks for your reply. I was also thinking of such an approach if I can't actually hide.
Sreehari
A: 

There's nothing in the documentation to suggest bar items have a hidden property.

Why not set

self.navigationItem.leftBarButtonItem = nil;

when the user isn't editing, then set

self.navigationItem.leftBarButtonItem = whateverBarButtonItem;

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.

Danilo Campos
Neil beat me to it – exactly.
Danilo Campos
A: 

This works I tried it myself

self.navigationItem.leftBarButtonItem = nil;

self.navigationItem.hidesBackButton = YES;

Adrian Avendano
A: 

self.navigationItem.leftBarButtonItem = nil; works great but, stupid question, how to show it again??? Thanks!

Ruthy