swift - 使用协调器模式和 Storyboard 初始化 UINavigationController

标签 swift xcode storyboard

我目前正在将我的应用程序从 MVC 迁移到 MVVM。另外我想使用 Coordinator 模式。由于我在我的应用程序中使用 Storyboard,所以我在这里遇到了一个问题。

我成功地从 Storyboard 中实现了 View Controller 的实例化。但是,当我在 Coordinator 中初始化导航 Controller UINavigationController() 时,应用程序 - 当然 - 不使用我在 Storyboard 中设计的导航 Controller 的设计。

有没有一种方法可以从 Storyboard 初始化 Navigation Controller,类似于 View Controller 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")
}

关于swift - 使用协调器模式和 Storyboard 初始化 UINavigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55728541/

相关文章:

ios - 不同的图像取决于用户屏幕尺寸

ios - 团队环境中的 Storyboard与 Nib

c# - 如何将 Storyboard用于 1 个以上的目标对象?

ios - 如何获取 View Controller 的名称?

ios - 导航栏 rightbaritem 图像按钮错误 iOS 11

swift - 将解析指针设置为 PFUser 以外的类

ios - 适用于 iOS 应用程序的 CCAvenue 网关集成套件

objective-c - JSON解析看不懂

xcode - 在线有Mac + xcode虚拟实验室吗?

ios - 如果用户在 swift iOS 中点击两次,则取消 NSURLSession