简体   繁体   English

使用协调器模式和情节提要初始化UINavigationController

[英]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.

相关问题 用于替换 SplitViewController 中的 UINavigationController 的协调器模式 - Coordinator Pattern to replace UINavigationController in SplitViewController 协调器模式 - 使用 Storyboard 而不是 Xib - Coordinator pattern - Using Storyboard instead of Xib Swift,UIKit。 寻找协调器模式教程,没有 storyboard - Swift, UIKit. Looking for Coordinator pattern tutorial, NO storyboard 协调器模式没有推送到 NextViewController - coordinator pattern is not pushing to the NextViewController 带协调器模式的 TabBar Controller - TabBar Controller With Coordinator Pattern 如果 UINavigationController 在第一个故事板中,有没有办法在第二个故事板中显示 UINavigationController ? - Is there a way to show UINavigationController in the second storyboard if that UINavigationController in the first storyboard? 在协调器模式中重用 ViewController,Swift - Reuse ViewController in Coordinator pattern, Swift RxSwift + MVVM +协调器模式,如何依次等待协调器结果? - RxSwift + MVVM + Coordinator Pattern, How to wait for coordinator result sequentially? 避免再次初始化同一个故事板 - Avoid initializing the same storyboard again 功能差异,UINavigationController vs Only Storyboard Segue - Functional difference, UINavigationController vs Only Storyboard Segue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM