views:

280

answers:

1

I'm using a UITabBar without a controller. I want to remove tabs from the UITabBar if certain conditions are met. For example, my UITabBar has 4 tabs set up in interface builder. If the scores module is not enabled at compile time, it should remove the scores tab.

// 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
+1  A: 

Have you tried using the items property of the UITabBar? For instance:

// 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
Jeff Kelley
That did the trick! One caveat to note is that it's arrayWithArray; arrayWithItems doesn't exist.
Typeoneerror
Whoops. Mental error on my part there.
Jeff Kelley