Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide UIToolbar UIBarButtonItems

I have a UIToolbar that I set up using IB with three buttons, left, middle and right. In some situations I would like to not display the middle button. Does anybody know of a way to hide a specific button on inside a UIToolBar? There is no hide property, all I can find is setEnable but this still leaves the button causing users to wonder what its purpose is. I would like to only display it in situations that it actually has a use.

Thanks in advance!

like image 616
jmurphy Avatar asked Jun 04 '10 04:06

jmurphy


People also ask

How do I hide items in navigation bar?

Go to your Navbar settings and find the navigation item you want to hide for a particular page. Click to edit and assign it a classname. You could assign it something like "hide-navigation-item."


2 Answers

Reset the items:

-(void)setItems:(NSArray *)items animated:(BOOL)animated

You can get the current items using the items property, then just remove the one you don't want to show and pass in the new NSArray.

As you can see, you can also animate it to make it clear to the user.

like image 177
Chris Cooper Avatar answered Sep 22 '22 12:09

Chris Cooper


Rather than guessing at the index, I added an IBOutlet for the UIBarButtonItem and then removed it by name:

NSMutableArray *toolBarButtons = [self._toolbar.items mutableCopy];
[toolBarButtons removeObject:self._selectButton]; // right button
[self._toolbar setItems:toolBarButtons];

And of course it helps to connect the outlets in the designer :)

like image 25
Nico teWinkel Avatar answered Sep 21 '22 12:09

Nico teWinkel