使用NavigationController ID加载ViewController

时间:2017-05-23 02:44:34

标签: swift

我需要帮助,我想在成功登录后通过调用他的NavigationController(仅带标识符)启动我的ViewController。

我尝试了这段代码,但它并没有加载。

     let homeController = self.storyboard!.instantiateViewController(withIdentifier: "NavigationController") 
    let homeController = homeController
viewControllers = [homeController]

ViewController with NavigationController

1 个答案:

答案 0 :(得分:0)

let homeController = self.storyboard!.instantiateViewController(withIdentifier: "NavigationController") 

上面的代码将返回UINavigationController。你应该通过调用它的第一个子节点来获取它的viewController。试试这个

// get navigation controller
let navController = self.storyboard!.instantiateViewController(withIdentifier: "NavigationController") as! UINavigationController

// get its first child
if let homeController = navController.viewControllers.first {
    viewControllers = [homeController]
}