gpt4 book ai didi

swift - 使用 NavigationController ID 加载 ViewController

转载 作者:行者123 更新时间:2023-11-30 12:26:34 25 4
gpt4 key购买 nike

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

我尝试了这段代码,但它无法加载。

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

ViewController with NavigationController

最佳答案

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]
}

关于swift - 使用 NavigationController ID 加载 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44124947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com