[英]Initializing UINavigationController with Coordinator Pattern and Storyboard
I am currently working on the migration of my app from MVC to MVVM. 我目前正在将我的应用程序从MVC迁移到MVVM。 In addition I would like to use the Coordinator pattern. 另外,我想使用协调器模式。 Since I use storyboards in my apps, I encountered a problem here. 由于我在应用程序中使用情节提要,因此在这里遇到了问题。
I successfully implemented the instantiation of view controllers from the storyboard. 我成功地从情节提要中实现了视图控制器的实例化。 But when I initialize the navigation controller UINavigationController()
in the Coordinator, the app - of course - doesn't use the design of the navigation controller as I designed it in the storyboard. 但是,当我在Coordinator中初始化导航控制器UINavigationController()
时,该应用程序-当然-不使用在情节提要中设计的导航控制器的设计。
Is there a way to initialize a Navigation Controller from the Storyboard similar to the View Controller storyboard.inistantiateViewController(withIdentifier)
? 有没有一种方法可以从情节提要中初始化导航控制器,类似于视图控制器storyboard.inistantiateViewController(withIdentifier)
?
I just tried this an it works. 我只是试过了,这行得通。 Are you doing something like this? 你在做这样的事吗?
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")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.