Programmatically set the initial view controller using Storyboards

前端 未结 22 2227
感情败类
感情败类 2020-11-22 15:00

How do I programmatically set the InitialViewController for a Storyboard? I want to open my storyboard to a different view depending on some condition which may

22条回答
  •  旧时难觅i
    2020-11-22 15:15

    Swift 4, Xcode 9

    in file AppDelegate.swift

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let firstVC = storyboard.instantiateViewController(withIdentifier: "firstViewController") as! firstViewController
        self.window?.rootViewController = firstVC
    }
    

提交回复
热议问题