简体   繁体   中英

Initializing UINavigationController with Coordinator Pattern and Storyboard

I am currently working on the migration of my app from MVC to 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.

Is there a way to initialize a Navigation Controller from the Storyboard similar to the View Controller 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")
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM