UIMoreNavigationController和UITabBarController的问题

这个问题一直困扰着我,但是我想我终于明白了什么是错的。 我我现在只需要一个解决scheme…

这是应用程序的背景。 用户可以使用大约6个不同的选项卡,使用UITabBarController进行显示。 这些选项卡中的每一个都是UINavigationController中的自定义UIViewController子类。 所有6个选项卡都设置在一个nib文件(MainWindows.xib)中。

我需要能够隐藏和显示不同的标签,取决于用户是否login,以及他们login谁。 我有这样的工作:

在应用程序启动(应用程序:didFinishLaunching:…),六个选项卡被存储到我有一个NSMutableArray。 这工作正常…

当用户login或注销时,我从NSMutableArray访问他可以使用的选项卡,并将它们添加到UITabBarController中,如下所示:

[tabBar setViewControllers: [NSArray arrayWithObjects: [viewControllers objectAtIndex:1], [viewControllers objectAtIndex:5], nil] animated:YES]; 

viewControllers是我之前用6个选项卡做的NSMutableArray。 在我创buildNSLog之后做这个,这就是我所期望的:

 2012-02-24 11:45:57.690 [redacted][26155:207] ( "<UINavigationController: 0x8249db0>", "<UINavigationController: 0x841a3f0>", "<UINavigationController: 0x824be40>", "<UINavigationController: 0x824dbd0>", "<UINavigationController: 0x824e810>", "<UINavigationController: 0x841dfb0>" ) 

但是,当我从最后一个自定义视图控制器,这是在列表中的最后一个导航控制器中打印self.parentViewController的值,我得到这个:

 2012-02-24 11:54:51.247 [REDACTED][26306:207] <UIMoreNavigationController: 0x826ab00> 2012-02-24 11:54:51.248 [REDACTED][26306:207] <UITabBarController: 0x8257c50> 

第一行是self.parentViewController,第二行是self.parentViewController.parentViewController

这似乎表明,heirachy是:

UITabBarController – > UIMoreNavigationController – > MyCustomController

不过,当我打印[self.parentViewController.parentViewController viewControllers]

我仍然得到:

 ( "<UINavigationController: 0x8259770>", "<UINavigationController: 0x825aa60>", "<UINavigationController: 0x825bec0>", "<UINavigationController: 0x82612c0>", "<UINavigationController: 0x8261ec0>", "<UINavigationController: 0x8263b00>" ) 

UIMoreNavigationController去了哪里? 任何人都可以解释发生了什么事? 我遇到与此相关的问题,因为我使用该数组,但是最后一个UINavigationController不是它声称的对象。

我有一个预感,苹果是摆弄幕后的对象,以便使程序员更容易…

我会尝试回答你关于代码结构,如何使用不同的对象或testing代码的任何问题。 非常感谢你提前。

其实Tabbar的moreViewController是一个UIMoreNavigationController 。 (你可以看看GitHub上的私有头文件 )

正如文档所述,viewController属性只包含已添加到tabbar的viewControllers: You must also not look for the More navigation controller in the array of view controllers stored in the viewControllers property. The tab bar controller does not include the More navigation controller in that array of objects. You must also not look for the More navigation controller in the array of view controllers stored in the viewControllers property. The tab bar controller does not include the More navigation controller in that array of objects.

在这里看到文档: UITabbarViewController 。

无论如何,我不明白,你的问题到底是什么。 如果您需要访问UIMoreNavigationController请通过UITabBarViewControllermoreNavigationController属性执行此操作。

但是'viewControllers'属性总是只包含你添加到TabBar的那些ViewController。

既然你没有说出你的实际问题,我什么都不能说。 但是我确定没有UIMoreNavigationController这样的类。 “更多”导航控制器只是一个由UITabBarControllerpipe理的UINavigationController来保存任何多余的子控制器。 请参阅Apple的UITabBarController参考 ,但您也可以在UIKit框架头文件UITabBarController.h仔细检查。

相应地,我无法在显示<UIMoreNavigationController: 0x826ab00>位置重现您的debugging输出。 在我的环境(SDK 5.0)中,我只是得到<UINavigationController: 0x12345678> ,而不pipe我是否检查自定义视图控制器的父级或标签栏控制器的子级。

只是为了确认一个问题。 我相信,在UITabBarController创buildUIMoreNavigationController的情况下,使用setViewController:会中断。 问题是,当更改标签栏的视图控制器,更多的导航控制器没有正确维护 – 控制器层次结构被损坏。 我已经提交了一个苹果的错误,但还没有收到答复。

  • 哈拉尔