Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Lakario

macrumors member
Original poster
Oct 29, 2008
30
0
I have a UIToolbar that I want to add/remove buttons from based on context, but looking at the class definition the UIToolbar uses a static NSArray for it's item collection. Short of overwriting the whole items array with another array is there any way to add or remove buttons at run time?
 

italiano40

macrumors 65816
Oct 7, 2007
1,080
0
NY
you can rename the buttons and based on the name of the button i would then run the method or action during run time
 

Lakario

macrumors member
Original poster
Oct 29, 2008
30
0
you can rename the buttons and based on the name of the button i would then run the method or action during run time

What about enabling or disabling a button altogether? I don't see anything to that effect in the UIBarButtonItem class reference. :(
 

Lakario

macrumors member
Original poster
Oct 29, 2008
30
0
Alternatively, I could keep an NSMutableArray local to the view that contains the items I want to display on the bar and then call setItems on the Toolbar with the modified items array. Would that be better than trying to tweak the items in the static array?
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
You can keep two arrays and swap them. You can put the same buttons in both arrays, except for those that are different. It's easy, works fine.

I build one in IB. Then in viewDidLoad I build the second one using the buttons from the first one that I want to reuse.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.