Remove tab from UITabBar without UITabBarController
I am using UITabBar without a controller. I want to remove tabs from UITabBar when certain conditions are met. For example, my UITabBar has 4 tabs configured in the interface builder. If a grading module is not included at compile time, it should remove the grading 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
+2
a source to share
1 answer
Have you tried using the items
property 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
+4
a source to share