UIMoreNavigationController和UITabBarController的问题 [英] Issues with UIMoreNavigationController and UITabBarController

查看:137
本文介绍了UIMoreNavigationController和UITabBarController的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题困扰了我一段时间,但我想我终于找出了什么是错的;我我现在只需要一个解决方案...

This problem has been plaguing me for a little while, but I've think I've finally figured out what's wrong; I think I just need a solution now...

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

Here's the background on the app. There are about 6 different tabs which the user can use, displayed using a UITabBarController. Each of these tabs is a custom UIViewController subclass, inside a UINavigationController. All 6 tabs are set up inside a nib file (MainWindows.xib).

我需要能够隐藏并显示不同的选项卡,具体取决于用户是否已登录与否,以及他们登录的对象。我有这样的工作:

I need to be able to hide and show different tabs depending on if the user is logged on or not, and who they're logged into. I have this working like so:

在应用程序启动时(应用程序:didFinishLaunching:...),六个选项卡存储在我拥有的NSMutableArray中。这很好用...

On app launch (application: didFinishLaunching: ...), the six tabs are stored into a NSMutableArray which I have. This works fine...

当用户登录或退出时,我从NSMutableArray访问他可以使用的标签,并将它们添加到UITabBarController中所以:

When a user logs in or out, I access the tabs that (s)he can use from the NSMutableArray and add them to the UITabBarController like so:

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

viewControllers是我之前用6个标签制作的NSMutableArray。在我创建之后立即对它进行NSLog,这就是我所期望的:

viewControllers is the NSMutableArray which I made earlier with the 6 tabs. Doing NSLog on it just after I create it gives this, which is what I expect:

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

然而,当我从最后一个自定义视图控制器打印self.parentViewController的值时,该控制器位于该列表中的最后一个导航控制器内,我明白了:

However, when I print the value of self.parentViewController from the last custom view controller, which is inside the last navigation controller in that list, I get this:

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

The first line is self.parentViewController, the second is self.parentViewController.parentViewController

这似乎表明heirachy是:

This seems to indicate the heirachy is:

UITabBarController - > UIMoreNavigationController - > MyCustomController

UITabBarController -> UIMoreNavigationController -> MyCustomController

然而,当我打印[self.parentViewController.parentViewController viewControllers]

However when I print [self.parentViewController.parentViewController viewControllers]

我仍然得到:

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

UIMoreNavigationController去了哪里?谁能解释一下发生了什么?我遇到了与此相关的问题因为我使用了那个数组,但最后一个UINavigationController不是它声称的对象。

Where's the UIMoreNavigationController gone? Can anyone explain what's going on? I'm encountering problems related to this because I use that array, however the last UINavigationController is not the object it claims to be.

我有预感苹果正在摆弄与幕后的对象一起使程序员更容易...

I have a hunch that apple is fiddling with the objects behind the scenes in order to make it easier for the programmer...

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

I'll try and reply to any questions you have with how the code is structured, how I use different objects, or to test some code. Thank you very much in advance.

推荐答案

实际上Tabbar的moreViewController是 UIMoreNavigationController 。 (你可以看一下 GitHub上的私人标题

Actually the moreViewController of the Tabbar IS a UIMoreNavigationController. (You can have a look at the private header on GitHub)

正如文档所述,viewController属性只包含viewControllers,您已将其添加到标签栏:您还必须没有在viewControllers属性中存储的视图控制器数组中查找更多导航控制器。标签栏控制器在该对象数组中不包含更多导航控制器。

As the documentation states, the viewController property only contains the viewControllers, which you have added to the tabbar: 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

See documentation here: UITabbarViewController.

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

Anyway i don't understand, what your problem exactly is. If you need to access the UIMoreNavigationController do it via the moreNavigationController property of the UITabBarViewController.

但'viewControllers'属性始终只保存那些已添加到TabBar的ViewControllers。

But the 'viewControllers' property always only holds those ViewControllers, that you have added to the TabBar.

这篇关于UIMoreNavigationController和UITabBarController的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆