簡體   English   中英

使用協調器模式和情節提要初始化UINavigationController

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM