我正在使用没有控制器的UITabBar。如果满足某些条件,我想从UITabBar中删除选项卡。例如,我的UITabBar在界面构建器中设置了4个选项卡。如果在编译时未启用score模块,则应删除score选项卡。
// defined in IB
#define kTabScores 1
UITabBar *_tabBar;
// in viewDidLoad
#if !INCLUDE_SCORES_SUPPORT
// this doesn't seem to work
[[_tabBar viewWithTag:kTagScores] removeFromSuperview];
#endif
答案 0 :(得分:4)
// defined in IB
#define kTabScores 1
UITabBar *_tabBar;
// in viewDidLoad
#if !INCLUDE_SCORES_SUPPORT
NSMutableArray *newItems = [NSMutableArray arrayWithArray:_tabBar.items];
[newItems removeObjectAtIndex:0]; //your index here.
[_tabBar setItems:newItems animated:YES];
#endif