OGeek|极客世界-中国程序员成长平台

标题: iphone - UINavigationController 嵌套在 moreViewController 中的问题 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:39
标题: iphone - UINavigationController 嵌套在 moreViewController 中的问题

我有包含一些 UINavigationControllers 的 UITabbarMoreController。这些 UINavigationControllers 然后包含我的自定义 View Controller 。

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

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

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

由于我在 tabbar Controller 中有很多子 Controller ,所以 tabbar Controller 创建了一个 moreNavigationController。如果我打开 moreNavigationController 下的 View Controller 并调用 [self parentViewController] 它会返回一个带有 UIMoreNavigationController 类的神秘对象

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



Best Answer-推荐答案


简而言之,你不能。

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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4