So In my app, I use a storyboard, and the initial viewController is a UITabBarController. What I want to do is when the app launches, I want to be able to set wheather the tabBarController has 3 items or 4. So in the appDel, I plan to check weather that user should see 3 or 4 tabs, and then the tabBarController should reflect that.
I tried subclassing the tabBarController, but the its not working:
@implementation TabBarController
-(id) init{
if ((self = [super init])) {
[[[[self tabBar] items] objectAtIndex:2] setEnabled:YES];
[[[[self tabBar] items] objectAtIndex:3] setEnabled:NO];
[[[[self tabBar] items] objectAtIndex:3] setHidden:YES];
}
return self;
}
@end
Any help would be apprciated.
Thanks in advance.
I’m thinking the easier (probably not best) way to do this is by having the TabBar controller not be the initial view controller and creating two tab bar controllers. From your initial view you can decide with tab bar controller you will show. You can also have the two tab bar controllers linked to the same tabs/viewcontrollers (the ones that are repeated between them).
In the initial view controller you add some code to know which segue you will perform and voila.
Something like this:

I am looking into a code solution to this though (seems interesting!). Will update if I find anything.
EDIT:
Here’s the coded solution. (I am using storyboards but I am sure you can translate the code to work with nib files).
The first thing to do is create an instance of the storyboard:
Then instantiate the tabbarcontroller:
Then instantiate the new view controller you want to add to the tabbar:
This is the interesting part, you put all the view controller/tabs into an array and then add or remove views from that array. Then you set the view controllers of the tabbarcontroller to the modified array (I add one viewController and remove another).
Then you can just push your tab bar controller like this:
Here I am using storyboards and ARC, you can modify it for nibs and release the array if you’re not using ARC. This was fun to write! hope it helps! cheers!