1

I´m making an application that have an wizard at the first time the app runs. After that, it should present a UITabBarController.

The second time the user runs the app, it should just present the UITabBarController.

Since UITabBarController should be the rootViewController, is there a way to redefine the app rootViewController so, when the wizard ends, the TabBarController shows up??

Or is there a better way to accomplish that behavior?

Thanks!!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
eduardo.lopes
  • 482
  • 7
  • 16

2 Answers2

1

Use an unwind segue. When presenting your application, push UITabBarController onto the navigation stack. If this is the first run of your app, disable animation when pushing the tab bar controller, and push the first screen of your wizard on top of it. If it is not the first run, push the tab bar controller with animation.

When the user goes through the wizard to completion, use an unwind segue to go back to the tab bar controller.

Community
  • 1
  • 1
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
1

Yes, you can redefine the window's root view controller from any controller that's currently displayed. You get the reference to the window with self.view.window. So, when your wizard ends, just instantiate your tab bar controller and change the root:

UITabBarController *tbc = [self.storyboard instantiateViewControllerWithIdentifier:@"tbc"]; // or other instantiation method if not using a storyboard
self.view.window.rootViewController = tbc;

In the app delegate, put logic that determines whether this is the first run of the app, and if not, run this slightly modified code to launch the tab bar controller directly:

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UITabBarController *tbc = [sb instantiateViewControllerWithIdentifier:@"tbc"]; // or other instantiation method if not using a storyboard
self.window.rootViewController = tbc;
rdelmar
  • 103,982
  • 12
  • 207
  • 218