5

I have a Main.storyboard containing the root view controller of my app. However, I would like to display an onboarding view (without a navigation controller) on first app launch in order for the user to fill some data that's needed only once. So I was thinking about creating an Onboarding.storyboard, but I don't know how to choose which storyboard to set, where to do it (AppDelegate?) and when data is filled, how to change the current storyboard.

Thanks for your help.

Rob
  • 4,123
  • 3
  • 33
  • 53
  • 1
    ohh why two entry point. Just create a view (say IntroView) & check for the launch of the app. If user open for the first time then show IntroView otherwise show nextview. – Gagan_iOS Jun 05 '17 at 08:06
  • This has been asked many many times on Stack Overflow in Objective-C and Swift. You should be able to find an answer on one of the already existing questions :D – Fogmeister Jun 05 '17 at 08:09
  • This should be -somehow- a useful Q/A when using Swift 3: https://stackoverflow.com/questions/41811070/show-a-view-on-first-launch-only-swift-3 – Ahmad F Jun 05 '17 at 08:23
  • Also, for Objective C: https://stackoverflow.com/questions/12878162/how-can-i-show-a-view-on-the-first-launch-only – Ahmad F Jun 05 '17 at 08:26

2 Answers2

8

Try this for Swift 3.x, make sure you're setting Initial View Controller in both the storyboards. In your AppDelegate.swift file, application:didFinishLaunchingWithOptions

var storyboardName:String?
if someCondition {
    storyboardName = "Onboarding"
}else{
    storyboardName = "Main"
}

let storyboard = UIStoryboard(name: storyboardName, bundle: nil)

let intialVC = storyboard.instantiateInitialViewController()

self.window?.rootViewController = intialVC
Imad Ali
  • 3,261
  • 1
  • 25
  • 33
1

You need to change this in AppDelegate's didFinishLaunchingWithOptions method.This method call's during app launch every time.

How:

Consider this example. Store the values in NSUserdefaults and retrieve it during app launch.

Example

Objective C:

BOOL isCompletedSetupWizard =[[NSUserDefaults standardUserDefaults] boolForKey:@"isCompletedSetupWizard"];

if (isCompletedSetupWizard) 
{ 
   //Your code goes here
   //....
   //....
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    viewController = [storyboard instantiateViewControllerWithIdentifier:@"yourFirstView"];
    self.window.rootViewController = viewController;
}
else  
{
  //Your code goes here for another view controller.
  //....
  //....
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"onBoarding" bundle:nil];
    viewController = [storyboard instantiateViewControllerWithIdentifier:@"yourSecondView"];
    self.window.rootViewController = viewController;
}
Community
  • 1
  • 1
elk_cloner
  • 2,049
  • 1
  • 12
  • 13