Programmatically set the initial view controller using Storyboards

前端 未结 22 2225
感情败类
感情败类 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:06

    Thanks modified this as follows in AppDelegate:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) ->     Bool {
    //Some code to check value of pins
    
    if pins! == "Verified"{
            print(pins)
            self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
            let mainStoryboard: UIStoryboard = UIStoryboard(name: "HomePage", bundle: nil)
            let exampleViewController: UINavigationController = mainStoryboard.instantiateViewControllerWithIdentifier("SBHP") as! UINavigationController
    
            self.window?.rootViewController = exampleViewController
    
            self.window?.makeKeyAndVisible()
        }else{
            print(pins)
            self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
            let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let exampleViewController: UINavigationController = mainStoryboard.instantiateViewControllerWithIdentifier("SBUser") as! UINavigationController
    
            self.window?.rootViewController = exampleViewController
    
            self.window?.makeKeyAndVisible()
        }
    

提交回复
热议问题