假设我在 Storyboard中有三个 View Controller ,我想将它们全部加载到 View Controller 堆栈中,但我想选择哪个先出现在用户面前。如下所示,我想在加载时显示第三个 View ,而不是显示第一个,有什么胶水吗?
最佳答案
选项 1。使用 Storyboard,您会看到指向 ViewController 1 的箭头。将其拖动到 View Controller 2 或 3。
选项 2。在加载您的第一个 View Controller 时,您可以 instantiate whichever view you'd like in your viewDidLoad()
,前提是您已为每个 Storyboard View 提供一个 ID。
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "YourVCIdentifier")
self.present(controller, animated: true, completion: nil)
选项 3。In your AppDelegate file, you can do this.
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
}
关于ios - 如何加载所有 View Controller Storyboard,但跳过自然顺序并直接转到特定 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43795139/