2

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...

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:

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

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 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>"
)

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>

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

This seems to indicate the heirachy is:

UITabBarController -> UIMoreNavigationController -> MyCustomController

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

I still get:

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

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.

6
  • First of all if self.parentViewController.parentViewController is the tab bar controller, why would you expect that array to change?
    – dbrajkovic
    Feb 27, 2012 at 18:47
  • Secondly, where is your UIMoreNavigationController created? If it's created in your last custom view controller, the tab bar controller wouldn't know anything about it. The array of view controllers in the tabbarcontroller does not define the view controller hierarchy. Nor does changing that hierarchy within one of the custom views affect that array of view controllers.
    – dbrajkovic
    Feb 27, 2012 at 18:57
  • It's not my UIMoreNavigationController. That's the issue, it's not bring created by me. I'm about 100% sure there's no class in my project called UIMoreNavigationController... I'll try and upload a minimal project which still shows that class later.
    – Tom H
    Feb 28, 2012 at 8:44
  • I find it very strange that your log has evidence of a UIMoreNavigationController class at all - AFAIK not even iOS has such a class. But maybe I am just out-of-date... which version of the iOS SDK do you use?
    – herzbube
    Feb 29, 2012 at 12:23
  • 1
    I don't know if you managed to fix this issue (even though you've accepted an answer) but I had the exact same issue and managed to track this down to how the UITabBarController is created. Rather than using [[UITabBarController alloc] initWithCoder:nil], instead use [[UITabBarController alloc] init]. This may seem obvious but i've just wasted 2hours trying to fix this!
    – Zack Brown
    May 31, 2012 at 14:13

3 Answers 3

4
+50

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

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.

See documentation here: UITabbarViewController.

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.

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

4
  • Sorry for being picky, but I maintain that there is no such thing as a UIMoreNavigationController class. I don't know where you see this class name in the documentation you are referencing - the property named moreNavigationController is clearly documented to be an instance of class UINavigationController. In all other respects: Good answer!
    – herzbube
    Mar 10, 2012 at 15:07
  • 4
    Its not documented as that class. But if you have a look in the debugger, you will always see that class name. Obviously it has to be a subclass of UINavigationController, because the property is defined as it. If you want to have a look at the header, look here: github.com/kennytm/iphone-private-frameworks/blob/master/UIKit/…
    – calimarkus
    Mar 11, 2012 at 10:09
  • Looking in the header for UITabBarController, you can clearly see: UINavigationController *_moreNavigationController; - There is no such class as UIMoreNavigationController. The UIKit framework doesn't contain this class either.
    – Zack Brown
    May 31, 2012 at 14:04
  • 2
    jaydee3 is correct. You shouldn't comment when you do not know what you are talking about. If you use the console to print out the tab bar controller's moreNavigationController, you'll see this. (lldb) po [tbc moreNavigationController] (UINavigationController *) $1 = 0x0fa51400 <UIMoreNavigationController: 0xfa51400> UIMoreNavigationController is clearly a (private) subclass of UINavigationController.
    – Christian
    Dec 18, 2012 at 22:56
1

Since you don't say what your actual problem is, I can't say anything about that. But I'm quite sure that there is no such class as UIMoreNavigationController. The "More" navigation controller is just a UINavigationController managed by UITabBarController to hold any surplus child controllers. See Apple's UITabBarController reference, but you can also double-check in the UIKit framework header file UITabBarController.h.

Correspondingly, I was unable to reproduce your debug output where you show <UIMoreNavigationController: 0x826ab00>. In my environment (SDK 5.0), I just get <UINavigationController: 0x12345678>, regardless of whether I check my custom view controller's parent, or the tab bar controller's children.

5
  • When you ran that test and couldn't reproduce, was that a tab bar item beyond the 5th one (if you see what I mean, so it was in the more display, rather than the default 4 tabs)? I think that it only appears there... Seems like a strange bug, I can confirm that there's definitely no class called UIMoreViewController (or anything close) anywhere in my project...
    – Tom H
    Feb 28, 2012 at 10:58
  • @TomH Yes, the custom view controller I tested with was under "More". I ran the test in the iPad simulator, landscape mode, so there were something like 6 tabs before "More". Sorry for the delay in answering, I am not on stackoverflow.com every day.
    – herzbube
    Feb 29, 2012 at 12:18
  • Don't worry about the delay. I'm using iOS 5... But not the very very latest version of Xcode (its a huge download...) so I'll try updating that.
    – Tom H
    Mar 1, 2012 at 0:16
  • Here's a little header file I found online showing that maybe UIMoreNavigationController does exist, but its just private for all intents and purposes... I might have to find another way to do what I'm doing. github.com/comex/spirit/blob/master/igor/headers/dumpedUIKit/…
    – Tom H
    Mar 1, 2012 at 0:17
  • (sorry for comment innundation) I think that the UIMoreNavigationController may be the navigation controller which displays the list of tabs to press when you click "More" on the tab bar. The reason it appears when I do self.parentViewController is because the navigationcontroller I made manually was pushed onto this "more navigation controller" as a child, so it'd appear when its row was tapped in the "More" list of tabs. I'll run some more tests tomorrow to see if this is the case.
    – Tom H
    Mar 1, 2012 at 0:24
1

Just to confirm a have the same problem. I believe that using setViewController: is broken in situations a UIMoreNavigationController has been created by the UITabBarController. The issue is that when changing the tab bar's view controllers, the more navigation controller is not correctly maintained - the controller hierarchy is getting corrupted. I have filed a bug with Apple but have not yet received a reply.

  • Harald
1
  • Yes I discovered the issue after a shit-ton of testing and guided by the answers on here, although they weren't optimal. The final issue related to a UIViewController getting orphaned. So I retained my own copies of all UIViewControllers I added to the TabBarController, rather than using the list which it provided in the form of the viewControllers property.
    – Tom H
    May 14, 2012 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.