我目前正在将我的应用程序从 MVC 迁移到 MVVM。另外我想使用 Coordinator 模式。由于我在我的应用程序中使用 Storyboard,所以我在这里遇到了一个问题。
我成功地从 Storyboard 中实现了 View Controller 的实例化。但是,当我在 Coordinator 中初始化导航 Controller UINavigationController()
时,应用程序 - 当然 - 不使用我在 Storyboard 中设计的导航 Controller 的设计。
有没有一种方法可以从 Storyboard 初始化 Navigation Controller,类似于 View Controller storyboard.inistantiateViewController(withIdentifier)
?
最佳答案
我刚刚试过了,效果不错。你在做这样的事情吗?
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let nc = storyboard.instantiateInitialViewController() as? UINavigationController {
print("got the nav controller")
}
// or if it's not the initial, you have to set the id in the storyboard
if let nc = storyboard.instantiateViewController(withIdentifier: "Nav") as? UINavigationController {
print("got the nav controller")
}
关于swift - 使用协调器模式和 Storyboard 初始化 UINavigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55728541/