two tab bar controllers

I want to make two tab bar controllers.

One for group A and the other for group B.

How to branch them?

Can I get some hints?

Answered by PBK in 82591022

I think this will work if you are not using Storyboard. (Not sure how to do it if you are using Storyboard.)


in AppDelegate define global variables


UITabBarController *tabBarController1;

UITabBarController *tabBarController2;


then in didFinishLaunchingWithOptions;

    tabBarController1=[[UITabBarController alloc] init];
    tabBarController1.delegate=self;
    tabBarController2=[[UITabBarController alloc] init];
    tabBarController2.delegate=self;


then somewhere and certainly execute before leaving didFinishLaunchingWithOptions:

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if(groupAIsBeingDisplayed){
    window.rootViewController = tabBarController1;
}else{
     window.rootViewController = tabBarController2;
}

[window makeKeyAndVisible];

You need a view and two UITabBar components as subviews. Of course, the parent view controller must be set as delegate to both of them in order to handle the user interactoins.

Accepted Answer

I think this will work if you are not using Storyboard. (Not sure how to do it if you are using Storyboard.)


in AppDelegate define global variables


UITabBarController *tabBarController1;

UITabBarController *tabBarController2;


then in didFinishLaunchingWithOptions;

    tabBarController1=[[UITabBarController alloc] init];
    tabBarController1.delegate=self;
    tabBarController2=[[UITabBarController alloc] init];
    tabBarController2.delegate=self;


then somewhere and certainly execute before leaving didFinishLaunchingWithOptions:

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if(groupAIsBeingDisplayed){
    window.rootViewController = tabBarController1;
}else{
     window.rootViewController = tabBarController2;
}

[window makeKeyAndVisible];

I draw 2 tabbarviewcontrols in the stroyboard,

how to connect tabBarController1 or tabBarController2 into the tabbarcontrols in the storyboard?

two tab bar controllers
 
 
Q