我目前正在将我的应用程序从MVC迁移到MVVM。此外,我还想使用协调器模式。因为我在我的应用程序中使用了故事板,所以我在这里遇到了一个问题。
我成功地从故事板实现了视图控制器的实例化。但是当我在协调器中初始化导航控制器UINavigationController()时,应用程序--当然--并没有使用我在故事板中设计的导航控制器的设计。
有没有一种方法可以从故事板中初始化导航控制器,类似于视图控制器storyboard.inistantiateViewController(withIdentifier)
发布于 2019-04-17 22:04:40
我刚试过这个,它起作用了。你在做这样的事情吗?
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")
}https://stackoverflow.com/questions/55728541
复制相似问题