Iphone 嵌套在moreViewController中的UINavigationController存在问题
我有一个UITabArmonRecontroller,它包含一些UINavigationController。这些UINavigationController然后包含我的自定义视图控制器 因此,层次结构如下所示:Iphone 嵌套在moreViewController中的UINavigationController存在问题,iphone,ios,uinavigationcontroller,uitabbarcontroller,parentviewcontroller,Iphone,Ios,Uinavigationcontroller,Uitabbarcontroller,Parentviewcontroller,我有一个UITabArmonRecontroller,它包含一些UINavigationController。这些UINavigationController然后包含我的自定义视图控制器 因此,层次结构如下所示: UITabbarController - UINavigationController -> my custom UIViewController - ...(other children of UITabbarController look the same) 在自定
UITabbarController
- UINavigationController
-> my custom UIViewController
- ...(other children of UITabbarController look the same)
在自定义视图控制器中,我调用[self-parentViewController]
,它将返回一个UINavigationController。这确实发生了,我确实得到了一个UINavigationController,但只有当特定的UINavigationController不在moreNavigationController中时
由于tabbar控制器中有许多子控制器,因此tabbar控制器会创建一个moreNavigationController。如果我打开moreNavigationController下的viewcontroller并调用[self parentViewController]
,它将返回一个类为UIMoreNavigationController的神秘对象
我真的需要获取视图控制器的父级UINavigationController,而不是UIMoreNavigationController。此外,我还尝试使用[self-navigationController]
获得相同的结果。如何获取对viewcontroller的真正最近父级的引用?提前谢谢你的帮助 简而言之,你不能
苹果总是试图优化他们的代码。此处的优化之一是检查其UIMoreNavigationController
列表中显示的ViewController
是否为UINavigationController
类型。因为UIMoreNavigationController
本身是一个UINavigationController,所以它不想创建另一个UINavigationController
。它试图避免UINavigationController
嵌套
当您查看的头文件时,您会注意到它有一个变量
UINavigationController*\u原始导航控制器
这是您创建并希望访问的原始UINavigationController
。不幸的是,您不能,因为UIMoreNavigationController
是私有的
解决方法(丑陋)
将NavigationController的引用推送到其堆栈上时,将其传递给其子级 看看这个答案,它有类似的问题,我见过,但它不能解决我的问题。我不需要访问moreNavigationController。我需要访问自己的UINavigationController,它嵌套在moreNavigationController中。谢谢你的帮助好的谢谢,这解释了为什么我尝试的另一种方法->使用
tabbarcontroller.selectedViewController
没有按我预期的方式工作