[英]Coordinator Pattern to replace UINavigationController in SplitViewController
[英]Initializing UINavigationController with Coordinator Pattern and Storyboard
我目前正在将我的应用程序从MVC迁移到MVVM。 另外,我想使用协调器模式。 由于我在应用程序中使用情节提要,因此在这里遇到了问题。
我成功地从情节提要中实现了视图控制器的实例化。 但是,当我在Coordinator中初始化导航控制器UINavigationController()
时,该应用程序-当然-不使用在情节提要中设计的导航控制器的设计。
有没有一种方法可以从情节提要中初始化导航控制器,类似于视图控制器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")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.