首页 > 解决方案 > 子视图控制器应该有父视图控制器,但实际父视图控制器是(UIViewControllerHierarchyInconsistency)

问题描述

我有一个将 UITabbarController 作为初始窗口的应用程序(登录后我将其设置为 rootViewController)

这个 tabbarController 有 4 个不同的选项卡,它们都是嵌入在 UINavigationController 中的 UIViewController。

在我的 tabbarController 中,当我进行初始配置时,我设置了如下标签:

我在网上查了一下,这种使用方式似乎是正确的。例如:https ://medium.com/@ITZDERR/uinavigationcontroller-and-uitabbarcontroller-programmatically-swift-3-d85a885a5fd0 。但是我从我的实时应用程序收到崩溃日志,如下所示

Crash, child view controller:<UINavigationController: 0x160b3400>
should have parent view controller:<ProfileViewController: 0x16098800>
but actual parent is:<MyApp.MainTabBarController: 0x16064c00>

这里的问题是崩溃说profileViewController应该是navigationController的父级但是我在navigationController中嵌入了profileViewController并添加为tabbarController的viewControllers,所以在我看来这个顺序是正确的。

我搜索了此崩溃,似乎我正在跳过使用 addChildViewController 或在某处删除父级的步骤,但无法弄清楚。

我找到了与此相关的链接,但没有一个帮助我解决了这个问题。

示例链接:

标签: swiftcrashuinavigationcontrollerchildviewcontrollerview-hierarchy

解决方案


推荐阅读