Iphone 从不带UITabBar控制器的UITabBar上卸下卡舌

Iphone 从不带UITabBar控制器的UITabBar上卸下卡舌,iphone,objective-c,uitabbar,Iphone,Objective C,Uitabbar,我用的是一个没有控制器的UITabBar。如果满足某些条件,我想从UITabBar中删除选项卡。例如,我的UITabBar在interface builder中设置了4个选项卡。如果在编译时未启用“分数”模块,则应删除“分数”选项卡 // defined in IB #define kTabScores 1 UITabBar *_tabBar; // in viewDidLoad #if !INCLUDE_SCORES_SUPPORT // this doesn't seem to

我用的是一个没有控制器的UITabBar。如果满足某些条件,我想从UITabBar中删除选项卡。例如,我的UITabBar在interface builder中设置了4个选项卡。如果在编译时未启用“分数”模块,则应删除“分数”选项卡

// 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
你有没有试过使用这个属性?例如:

// 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

成功了!需要注意的一点是,它是arrayWithArray;arrayWithItems不存在。