user69132
user69132

Reputation: 11

Presenting a different storyboard upon launch

I'd like to present a different storyboard scene to the user based on some conditions (if the user has previously logged in, show the welcome scene; if they're a new user, show the signup screen).

Whether the user has logged in previously will be stored in sqlite - but where should I check for this, and how can I load the default initial scene based on this?

I've looked at doing performSegue in the AppDelegate, but I don't think segue's are the right approach.

Any ideas how to go about this one? Thanks all!

Upvotes: 0

Views: 64

Answers (2)

NNikN
NNikN

Reputation: 3850

Hey This is what you can do , remove the main interface file from the settings and then using the following code.

  1. Step 1: Select the Project and then select General Settings.

enter image description here 2. Step 2

Use the below code with your conditions.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    self.window=[[UIWindow alloc] init];
    [self.window setFrame:[UIScreen mainScreen].bounds];

     if(signedIn){
     //Create Account Storyboard
    UIStoryboard *board=[UIStoryboard storyboardWithName:@"A" bundle:nil];
     [self.window setRootViewController:[board instantiateInitialViewController]];
     }else{
      //Signup StoryBoard
    UIStoryboard *board=[UIStoryboard storyboardWithName:@"B" bundle:nil];
     [self.window setRootViewController:[board instantiateInitialViewController]];
    }

    [self.window makeKeyAndVisible];

    return YES;
}

Upvotes: -1

nhgrif
nhgrif

Reputation: 62052

You need to use the app delegate's - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method.

First, you need to include the logic in here to determine which storyboard to load. Once you've determined which storyboard to load, the storyboard can be loaded as such:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"YOUR_STORYBOARD" 
    bundle:nil];

UIViewController *initialViewController = [storyBoard 
    instantiateInitialViewController];

[self.window setRootViewController:initialViewController];

Upvotes: 2

Related Questions