【发布时间】:2018-01-01 22:12:21
【问题描述】:
在我的应用中更改根目录时遇到问题。
我的应用程序的设计。
登录应用程序后,我想将 root vc 更改为 UITabBarViewController 以清理堆栈。
我遇到过很多问题。
-
在应用登录操作时将 vc 设置为标签栏 -> 或在底部 vc 中:
self.performSegue(withIdentifier: "goToMainTabBar", sender: nil) override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let vc = segue.destination as? TabBarViewController { UIApplication.shared.keyWindow?.rootViewController = vc } }
应用程序将崩溃:
Application tried to present modal view controller on itself. Presenting controller is TabBarViewController
-
下一个问题是如果我们在
TabBarViewControllerviewDidLoaded中设置一个根。UIApplication.shared.keyWindow?.rootViewController = self
UINavigationController 中嵌入的标签栏项目本身没有导航控制器,所以导航 vc 没有实例化?因为我什么时候会进入项目 vc child -> 我不能再回来了。
如果我不会;不更改根 vc,那么一切都很好。
【问题讨论】:
-
@Ercell0 我不这么认为,你读过我的 2 个问题吗?
-
是的,我做到了,也许你应该继续阅读这个问题,你需要将你的 VC 嵌入 UINavigationController 然后将其添加为根 VC:
.rootViewController = UINavigationController(rootViewController: tabVC)