这个问题已经困扰了我一段时间,但我想我终于弄明白了是什么问题;我认为我现在只需要一个解决方案...
这是应用程序的背景。用户可以使用大约 6 个不同的选项卡,使用 UITabBarController 显示。这些选项卡中的每一个都是 UINavigationController 中的自定义 UIViewController 子类。所有 6 个选项卡都设置在一个 nib 文件 (MainWindows.xib) 中。
我需要能够根据用户是否登录以及登录的用户来隐藏和显示不同的选项卡。我有这样的工作:
在应用程序启动时(应用程序:didFinishLaunching:...),六个选项卡存储在我拥有的 NSMutableArray 中。这很好用……
当用户登录或注销时,我从 NSMutableArray 访问他可以使用的选项卡,并将它们添加到 UITabBarController,如下所示:
[tabBar setViewControllers: [NSArray arrayWithObjects:
[viewControllers objectAtIndex:1],
[viewControllers objectAtIndex:5],
nil] animated:YES];
viewControllers 是我之前用 6 个选项卡制作的 NSMutableArray。在我创建它之后对它执行 NSLog 给出了这个,这是我所期望的:
2012-02-24 11:45:57.690 [redacted][26155:207] (
"<UINavigationController: 0x8249db0>",
"<UINavigationController: 0x841a3f0>",
"<UINavigationController: 0x824be40>",
"<UINavigationController: 0x824dbd0>",
"<UINavigationController: 0x824e810>",
"<UINavigationController: 0x841dfb0>"
)
但是,当我从最后一个自定义 View Controller 打印 self.parentViewController 的值时,它位于该列表中最后一个导航 Controller 内,我得到这个:
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
这似乎表明继承权是:
UITabBarController -> UIMoreNavigationController -> MyCustomController
但是当我打印 [self.parentViewController.parentViewController viewControllers] 时
我仍然得到:
(
"<UINavigationController: 0x8259770>",
"<UINavigationController: 0x825aa60>",
"<UINavigationController: 0x825bec0>",
"<UINavigationController: 0x82612c0>",
"<UINavigationController: 0x8261ec0>",
"<UINavigationController: 0x8263b00>"
)
UIMoreNavigationController 哪里去了?任何人都可以解释发生了什么事吗?我遇到了与此相关的问题,因为我使用了那个数组,但是最后一个 UINavigationController 并不是它声称的对象。
我有一种预感,苹果正在摆弄幕后的对象,以便让程序员更容易...
我会尽力回答您关于代码结构、我如何使用不同对象或测试某些代码的任何问题。非常感谢您。
最佳答案
实际上Tabbar的moreViewController是一个UIMoreNavigationController
。 (你可以看看 private header on GitHub )
如文档所述,viewController 属性仅包含您已添加到选项卡栏的 viewController:您也不得在 viewControllers 属性中存储的 View Controller 数组中查找更多导航 Controller 。选项卡栏 Controller 不包含该对象数组中的更多导航 Controller 。
请参阅此处的文档:UITabbarViewController .
反正我不明白,你的问题到底是什么。如果您需要访问 UIMoreNavigationController
,请通过 UITabBarViewController
的 moreNavigationController
属性进行访问。
但是 'viewControllers' 属性始终只包含那些已添加到 TabBar 的 ViewControllers。
关于ios - UIMoreNavigationController 和 UITabBarController 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9430427/