Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I dynamically hide a button from a view?

I would like to dynamically hide a button in one of my views depending on a certain condition.

I tried adding some code to the view controller's -viewWillAppear method, to make the button hidden before displaying the actual view, but I still don't know how to do that.

I have a reference to the button through an IBOutlet, but I'm not sure how to move forward from here. For reference, this is a UIBarButtonItem instance.

like image 981
jpm Avatar asked Nov 10 '08 01:11

jpm


People also ask

How do you hide a button?

You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <button> is not visible, but maintains its position on the page.

How do I hide a button in Visual Studio?

Click View > View Textboxes. The two textboxes you added should disappear. To hide a control, simply set it's Visible property to False.


1 Answers

If you're trying to hide a UIBarButtonItem, you'll actually have to modify the contents of the parent bar. If it's a UIToolBar, you'll need to set the bar's items array to an array that doesn't include your item.

NSMutableArray     *items = [[myToolbar.items mutableCopy] autorelease]; [items removeObject: myButton]; myToolbar.items = items; 
like image 186
Ben Gottlieb Avatar answered Oct 12 '22 02:10

Ben Gottlieb