Modify Items in a UIToolbar

Discussion in 'iOS Programming' started by Lakario, Nov 7, 2008.

  1. Lakario macrumors member

    Oct 29, 2008
    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?
  2. italiano40 macrumors 65816


    Oct 7, 2007
    you can rename the buttons and based on the name of the button i would then run the method or action during run time
  3. Lakario thread starter macrumors member

    Oct 29, 2008
    What about enabling or disabling a button altogether? I don't see anything to that effect in the UIBarButtonItem class reference. :(
  4. Lakario thread starter macrumors member

    Oct 29, 2008
    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?
  5. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    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.

Share This Page