Jacek Kwiecień
Jacek Kwiecień

Reputation: 12649

Switching between two UITabBarController?

I'm developing storyboard based app and I'm wondering if I could have 2 TabBarControllers - one is for user not logged in and another one for user logged in. Can I swap NotLoggedInTabBarController to LoggedInTabBarController on login button action?

Upvotes: 1

Views: 285

Answers (2)

Tala
Tala

Reputation: 8928

You can add IBAction to your button with check of this condition and instantiate needed controller.

ViewController *viewController = nil;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
YourViewController *viewController = nil;
if ([userManager isLoggedIn]) {
     viewController = (YourViewController *)[storyboard instantiateViewControllerWithIdentifier:@"LoggedInViewControllerIdentifier"];
} else {
     viewController = (YourViewController *)[storyboard instantiateViewControllerWithIdentifier:@"NotLoggedInViewControllerIdentifier"];
}
[self.navigationController pushViewController:viewController animated:YES];

in your storyboard you'll have to set storyboard id in Identity inspector

EDIT

If you are not using navigationController to route to correct logged/notlogged controllers then your could do sth like that:

MyAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.transitionController transitionToViewController:viewController
                                                 withOptions:UIViewAnimationOptionTransitionFlipFromRight];

Upvotes: 0

zbMax
zbMax

Reputation: 2818

If you add a Restoration ID to your viewControllers in the storyboard (identity inspector) you can instantiate a controller by calling the method instantiateViewControllerWithIdentifier:

In your case, maybe i would have instantiate a parent view controller, and when wanting to swap of tabBarcontroller, I would have called

[parentViewController.storyboard instantiateViewControllerWithIdentifier:@"tabBarController2"];

And then change controller displayed.

(Not tested, just some ideas...)

Upvotes: 1

Related Questions