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.
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
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With