简体   繁体   English

如何从LaunchScreen.Storyboard初始化ViewController

[英]How to Initialize ViewController from LaunchScreen.Storyboard

When I try to instantiate ViewController from Main.Storyboard in another ViewController I doing something like this: 当我尝试在另一个ViewController中从Main.Storyboard实例化ViewController时,我会执行以下操作:

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

Where Storyboard is "the UIStoryboard from which this UIViewController was created". Storyboard是“创建此UIViewController的UIStoryboard”。

However, I need to Instantiate ViewController from LaunchScreen.Storyboard at this time. 但是,此时我需要从LaunchScreen.Storyboard实例化ViewController。

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. 如果您需要立即启动应用程序,则不要在LaunchScreen.Storyboard编写代码,可以编写代码FinishedLaunching因为它是启动后不久要调用的第一种方法。 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. 不,您不能从LaunchScreen.Storyboard实例化ViewController。

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. 您无法在情节提要中指定自定义类名称,并且不能期望系统在此阶段通过调用viewDidLoad为您提供执行代码的选项。 Remember, the app hasn't launched yet. 请记住,该应用尚未启动。

Refer: replacing-launch-images-with-storyboards 请参阅: 用故事板替换启动图像

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单个 Launchscreen.storyboard 启动画面未按比例显示在 Xamarin Z645024253191298AE688A3 中的各种 iOS 设备中 - Single Launchscreen.storyboard splash image not displaying proportionally in various iOS devices in Xamarin Forms F#:从 ViewController 中的故事板访问 UI 元素? - F#: Accessing UI Elements from storyboard in ViewController? C#PresentViewController到storyboard中的viewcontroller - C# PresentViewController to a viewcontroller in storyboard 如何从ViewModel开始StoryBoard? - How to Begin a StoryBoard from ViewModel? 如何在xaml中声明一个故事板并从代码中运行它 - how declare a storyboard in xaml and run it from code 如何读取情节提要属性“从”或“到”(等) - How to read Storyboard property “From” or “To” (etc.) 如何使用从一个 ViewController 到另一个 ViewController 的数据以扩展第一个 ViewController 的信息? - How can I use the data from one ViewController to another in order to expand the first ViewController's information? 应用程序崩溃,NSInvalidLayoutConstraintException,iOS故事板设计器ViewController中的红色惊叹号 - App crashes, NSInvalidLayoutConstraintException, red exclamation in iOS storyboard designer ViewController 从一个ViewController获得图像,如何在另一个ViewController上显示它 - Got an image from one ViewController, how can I display it on the other ViewController 如何从子项目初始化DbContext? - How to initialize DbContext from child project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM