How can I dynamically hide a button from a view?

前端 未结 12 2147
执念已碎
执念已碎 2020-12-04 21:24

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 -viewWillAppe

12条回答
  •  时光说笑
    2020-12-04 22:19

    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;
    

提交回复
热议问题