PDA

View Full Version : Modify Items in a UIToolbar




Lakario
Nov 7, 2008, 12:31 PM
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
Nov 7, 2008, 12:36 PM
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
Nov 7, 2008, 01:03 PM
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
Nov 7, 2008, 01:16 PM
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
Nov 7, 2008, 10:35 PM
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.