views:

32

answers:

1

Hi everyone,

How can I remove a UITabBarItem from a UITabBar?

I haven't tried anything, because I haven't found anything from Google searches or the documentation for UITabBar, UITabBarController, or UITabBarItem.

Thanks in advance! :)

+5  A: 

UITabBar has an NSArray collection of items. Since the items property is an NSArray and not an NSMutableArray, you'd have to construct a new NSArray from the existing one devoid of the object you want to remove, then set the items property to the new array.

/* suppose we have a UITabBar *myBar, and an int index idx */
NSMutableArray modifyMe = [[myBar items] mutableCopy];
[modifyMe removeObjectAtIndex:idx];
NSArray *newItems = [[NSArray alloc] initWithArray:modifyMe];
[myBar setItems:newItems animated:true];
Mike Caron
Remember, `-[NSArray mutableCopy]` is your friend. Also, don't overlook `-[UITabBar setItems:animated:]`.
Sixten Otto
http://developer.apple.com is also your friend ;)
Mike Caron