Swift - pushViewController from appDelegate, rootViewController.navigationController is nil

前端 未结 7 718
無奈伤痛
無奈伤痛 2020-12-08 14:57

Having a problem following a few guides, specifically http://blog.originate.com/blog/2014/04/22/deeplinking-in-ios/

I\'m setting the url scheme and it\'s working wel

7条回答
  •  一整个雨季
    2020-12-08 15:19

    It seems that rootViewController actually is of type UINavigationController in my case, so casting it on declaration allowed me to call pushToViewController directly on it.

    func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool {
        let rootViewController = self.window!.rootViewController as! UINavigationController
        let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let profileViewController = mainStoryboard.instantiateViewController(withIdentifier: "InstructionVC") as! InstructionVC
        rootViewController.pushViewController(profileViewController, animated: true)
        return true
    
    }
    

提交回复
热议问题