删除UITabBarItem

esq*_*qew 5 iphone uitabbaritem uitabbar iphone-sdk-4.1

我怎样才能删除UITabBarItemUITabBar

我还没有尝试过什么,因为我还没有发现从谷歌搜索任何东西,或为文档UITabBar,UITabBarControllerUITabBarItem.

提前致谢!:)

Mik*_*ron 9

UITabBar有一个NSArray项目集合.由于items属性是NSArray而不是NSMutableArray,因此您必须从现有的NSArray构造一个没有要删除的对象的新NSArray,然后将items属性设置为新数组.

/* 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];
Run Code Online (Sandbox Code Playgroud)

  • 记住,` - [NSArray mutableCopy]`是你的朋友.另外,不要忽视` - [UITabBar setItems:animated:]`. (3认同)