如何加载所有视图控制器故事板,但跳过自然序列并直接转到特定视图? [英] How to load all view controllers storyboard, but skip the natural sequence and go direct to a specific view?

查看:21
本文介绍了如何加载所有视图控制器故事板,但跳过自然序列并直接转到特定视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在情节提要中有三个视图控制器,我想将它们全部加载到视图控制器堆栈中,但我想选择哪个首先显示给用户.如下所示,我想在加载时显示第三个视图,而不是显示第一个,任何胶水?

Suppose I have three view controllers inside a storyboard, I want to load all of them into view controllers stack, but I want to choose which one will appear first to the user. As shown below I would like to show the third view on load, instead to show the first, any glue?

推荐答案

选项 1. 使用故事板,您会看到指向 ViewController 1 的箭头.将其拖到 View Controller 2 或 3.

Option 1. Using storyboards, you see the arrow pointing to your ViewController 1. Drag that to View Controller 2 or 3.

选项 2. 在加载第一个视图控制器时,您可以viewDidLoad(),前提是您为每个故事板视图提供了一个 ID.

Option 2. On load of your first view controller, you can instantiate whichever view you'd like in your viewDidLoad(), provided you have given each storyboard view an ID.

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "YourVCIdentifier")
self.present(controller, animated: true, completion: nil)

选项 3.在您的 AppDelegate 文件中,您可以这样做.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    self.window = UIWindow(frame: UIScreen.main.bounds)

    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    let initialViewController = storyboard.instantiateViewController(withIdentifier: "YourVCIdentifier")

    self.window?.rootViewController = initialViewController
    self.window?.makeKeyAndVisible()

    return true
}

这篇关于如何加载所有视图控制器故事板,但跳过自然序列并直接转到特定视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆