首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用协调器模式和情节提要初始化UINavigationController

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

Stack Overflow用户
提问于 2019-04-17 21:21:43
回答 1查看 72关注 0票数 0

我目前正在将我的应用程序从MVC迁移到MVVM。此外,我还想使用协调器模式。因为我在我的应用程序中使用了故事板,所以我在这里遇到了一个问题。

我成功地从故事板实现了视图控制器的实例化。但是当我在协调器中初始化导航控制器UINavigationController()时,应用程序--当然--并没有使用我在故事板中设计的导航控制器的设计。

有没有一种方法可以从故事板中初始化导航控制器,类似于视图控制器storyboard.inistantiateViewController(withIdentifier)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-17 22:04:40

我刚试过这个,它起作用了。你在做这样的事情吗?

代码语言:javascript
复制
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")
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55728541

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档