iphone - UINavigationController 嵌套在 moreViewController 中的问题

标签 iphone ios uinavigationcontroller uitabbarcontroller parentviewcontroller

我有 UITabbarMoreController,其中包含一些 UINavigationController。这些 UINavigationController 然后包含我的自定义 View Controller 。

所以层次结构看起来像这样:

UITabbarController
 - UINavigationController
  -> my custom UIViewController
 - ...(other children of UITabbarController look the same)

在我的自定义 View Controller 中,我调用 [selfparentViewController] ,它应该返回一个 UINavigationController。这确实发生了,我确实得到了一个 UINavigationController,但只有当特定的 UINavigationController 不在 moreNavigationController 内时。

由于我在选项卡栏 Controller 中有很多子 Controller ,因此选项卡栏 Controller 创建了一个 moreNavigationController。如果我打开 moreNavigationController 下的 View Controller 并调用 [selfparentViewController] 它会返回一个带有 UIMoreNavigationController 类的神秘对象

我确实需要获取作为 View Controller 父级的 UINavigationController,而不是 UIMoreNavigationController。另外,我尝试使用 [self navigationController] 得到相同的结果。如何获得对 View Controller 真正最接近的父级的引用?提前感谢您的帮助!

最佳答案

简而言之,你不能。

Apple 总是尝试优化他们的代码。他们的优化之一是检查其 UIMoreNavigationController 列表中显示的 ViewController 是否为 UINavigationController 类型。因为 UIMoreNavigationController 本身就是一个 UINavigationController,所以它不想创建另一个 UINavigationController。它试图避免 UINavigationController 嵌套。

当你查看UIMoreNavigationController的头文件时你会注意到它有一个变量 UINavigationController* _originalNavigationController; 这实际上是您创建并想要访问的原始 UINavigationController。不幸的是你不能,因为 UIMoreNavigationController 是私有(private)的。

解决方法(丑陋)

当您将 NavigationController 插入其堆栈时,将其子级的引用传递给它们。

关于iphone - UINavigationController 嵌套在 moreViewController 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11965886/

相关文章:

ios - 无法为名为的类创建映射策略(Cocoa 错误 134110)

ios - 使用 UINavigationController 作为窗口的 Root View 时如何构建应用程序

部分屏幕区域中类似 iOS UINavigationController 的行为 (2016)

ios - 隐藏导航栏,具体取决于 View Controller 的显示方式

ios - 如何以不同的尺寸显示 2 个不同的原型(prototype)单元

iphone - 只允许用户按 UIButton 一次

iphone - iPhone中的sqlite查询导致泄漏

iphone - 在 iPhone 中根据触摸拖动旋转图像

iphone - CFNetwork 读取 http header Transfer-Encoding Identity 但 wireshark 显示分块

iphone - 模拟器无法在主 TableView 上启动