简体   繁体   中英

How to Initialize ViewController from LaunchScreen.Storyboard

When I try to instantiate ViewController from Main.Storyboard in another ViewController I doing something like this:

SplashViewController splashVC = Storyboard.InstantiateViewController("Splash") as SplashViewController;

Where Storyboard is "the UIStoryboard from which this UIViewController was created".

However, I need to Instantiate ViewController from LaunchScreen.Storyboard at this time.

You should not write code in LaunchScreen.Storyboard if you need to start your application immediately you can write your code FinishedLaunching as it is first method to be called soon after Launching. Write your code here.

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
    // Override point for customization after application launch.
    // If not required for your application you can safely delete this method

    return true;
}

No, you can't Instantiate ViewController from LaunchScreen.Storyboard.

The launch screen is what first appears when the user taps the app icon before the app is finished launching. It shows a single, static screen. It can't be dynamic and it can't use any custom classes or code.

And

You cannot specify a custom class name in the storyboard and expect the system to give you the option to execute code at this stage by calling viewDidLoad. Remember, the app hasn't launched yet.

Refer: replacing-launch-images-with-storyboards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM