【问题标题】:Problems with UINavigationController nested within moreViewControllerUINavigationController 嵌套在 moreViewController 中的问题
【发布时间】:2012-08-15 08:02:59
【问题描述】:

我有包含一些 UINavigationControllers 的 UITabbarMoreController。这些 UINavigationControllers 然后包含我的自定义视图控制器。

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

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

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

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

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

【问题讨论】:

  • 看看这个答案它有类似的问题stackoverflow.com/a/9567134/277021
  • 我见过,但它并没有解决我的问题。我不需要访问 moreNavigationController。我需要访问我自己的 UINavigationController,它嵌套在 moreNavigationController 中。感谢您尝试提供帮助

标签: iphone ios uinavigationcontroller uitabbarcontroller parentviewcontroller


【解决方案1】:

简而言之,你不能。

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

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

解决方法(丑陋)

当您将 NavigationController 的引用推送到它的堆栈时,将它们传递给它的子项。

【讨论】:

  • 好的,谢谢,这解释了为什么我尝试的其他方法 -> 使用 tabbarcontroller.selectedViewController 并没有按我预期的方式工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-07
  • 2015-04-02
  • 2017-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多