我有两个情节提要
当用户登录时,它从loginViewController移到ChatVC,我想使用ChatVC的嵌入式导航控制器。我在下面编写了代码,但是在这种情况下,要创建自己的新导航控制器。有什么方法可以使用App.storyboard的导航控制器。
guard let rootVC = UIStoryboard.init(name: "App", bundle: nil).instantiateViewController
(identifier: "MessaageVC") as? MessaageVC else {
return
}
let navigationController = UINavigationController(rootViewController: rootVC)
UIApplication.shared.windows.first?.rootViewController = navigationController
UIApplication.shared.windows.first?.makeKeyAndVisible()
如果您有自定义UINavigationController
类,则应替换as? UINavigationContoller
为您的类。您可以根据需要更改情节提要名称。
if let nav = UIStoryboard(name: "App", bundle: nil).instantiateViewController(withIdentifier: "yourNavigationControllerIdentifier") as? UINavigationController{
let rootVc = UIStoryboard(name: "App", bundle: nil).instantiateViewController(withIdentifier: "yourRootVCIdentifier")
nav.viewControllers = [rootVc]
UIApplication.shared.keyWindow?.rootViewController = nav
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句