我有 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/