Programmatically set the initial view controller using Storyboards

前端 未结 22 2368
感情败类
感情败类 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条回答
  •  忘掉有多难
    2020-11-22 15:23

    Swift 5 or above# make route view controller by this simple code. If you are using xcode 11 or above first initialise var window: UIWindow? in AppDelegate

    let rootVC = mainStoryboard.instantiateViewController(withIdentifier: "YOURCONTROLLER") as! YOURCONTROLLER
    
            navigationController.setNavigationBarHidden(true, animated: true)
            UIApplication.shared.windows.first?.rootViewController = UINavigationController.init(rootViewController: rootVC)
            UIApplication.shared.windows.first?.makeKeyAndVisible()
    

提交回复
热议问题