如何加载所有视图控制器故事板,但跳过自然序列并直接转到特定视图? [英] How to load all view controllers storyboard, but skip the natural sequence and go direct to a specific view?
问题描述
假设我在情节提要中有三个视图控制器,我想将它们全部加载到视图控制器堆栈中,但我想选择哪个首先显示给用户.如下所示,我想在加载时显示第三个视图,而不是显示第一个,任何胶水?
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屋!