I have code that works great for adding a button to the toolbar:
NSArray* toolbarItems = [NSArray arrayWithObjects:flexibleSpace,shuffleBarItem,flexibleSpace,nil];
self.toolbarItems = toolbarItems;
However, I also want to be able to remove toolbar items. When I use the below method, my application crashes:
NSArray* toolbarItems = [NSArray arrayWithObjects:flexibleSpace,nil];
self.toolbarItems = toolbarItems;
Does anyone know how I can dynamically alter the toolbar on the iPhone?
Thanks!
Change it into a
NSMutableArray
.When you want to remove items from the array:
Note that in this case you should not use
removeObject
since you have repeating objects in your array, and calling[ _toolbarItems removeObject: flexibleSpace ]
will actually remove both instances offlexibleSpace
in the array