0

I'm developing an iOS 7+ app, and I've been told to set a different initial view for the app depending on a parameter I won't know until runtime. One of the possible initial UIViewController is an UITabBarViewController, and the other one is an UINavigationController.

Is it possible to manage this using a storyboard? Or is it the only way to use separated nib files?

Thanks

AppsDev
  • 12,319
  • 23
  • 93
  • 186
  • Possible duplicate of [Programatically set the initial view controller using Storyboards](http://stackoverflow.com/questions/10428629/programatically-set-the-initial-view-controller-using-storyboards) – Lars Blumberg Apr 11 '16 at 16:22

3 Answers3

2

No need to use separate nib files, I do the same by following code in AppDelegate

- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    UIStoryboard *storyboard = self.window.rootViewController.storyboard;
    if(condition1) {
        UITabBarController *rootViewController= [storyboard instantiateViewControllerWithIdentifier:@"TabbarController"];
        [self setRootViewController:rootViewController];
    } else if(condition2) {
        UIViewController *rootViewController= [storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
        [self setRootViewController:rootViewController];
    } else {
        UIViewController *rootViewController= [storyboard instantiateViewControllerWithIdentifier:@"ViewController1"];
        [self setRootViewController:rootViewController];
    }
}

-(void)setRootViewController:(UIViewController *)rootViewController {
    self.window.rootViewController = rootViewController;
    [self.window makeKeyAndVisible];
}
Abhishek
  • 1,682
  • 2
  • 17
  • 29
0

You can specify the ID for your UITabBarViewController and UINavigationController in the storyboard.Then manually set the rootViewController of your app as the code below.

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = [board instantiateViewControllerWithIdentifier:@"TabBarController"];
[self.window makeKeyAndVisible];

}

WeaponJ
  • 103
  • 1
  • 5
0

I'm not sure if I understood you right, but try to use JLRoutes. Set your TabBarController as initial view controller in one storyboard and navigation controller will be initial in other storyboard. Then navigate between them using JLRoutes

Victorianec
  • 587
  • 1
  • 6
  • 15