I have UITabbarMoreController which contains a few UINavigationControllers. These UINavigationControllers then contain my custom view controllers.
So the hierarchy looks something like this:
UITabbarController
- UINavigationController
-> my custom UIViewController
- ...(other children of UITabbarController look the same)
From within my custom view controller I call [self parentViewController]
which should return a UINavigationController. And this really happens, I really do get a UINavigationController, BUT only when the particular UINavigationController is NOT inside moreNavigationController.
Since I have many children controllers in the tabbar controller, the tabbar controller creates a moreNavigationController. If I open a viewcontroller that is under moreNavigationController and call [self parentViewController]
it returns a mysterious object with class UIMoreNavigationController
I really need to get the UINavigationController that is parent of my view controller, not the UIMoreNavigationController. Also, I tried using [self navigationController]
with the same result. How can I get reference to the real closest parent of my viewcontroller? Thanks for help in advance!
In short, you can't.
Apple always try to optimise their code. One of their optimisation here is to check whether the
ViewController
displayed in the list of itsUIMoreNavigationController
is of typeUINavigationController
. BecauseUIMoreNavigationController
itself is a UINavigationController it does not want to create anotherUINavigationController
. It's trying to avoidUINavigationController
nesting.When you look at the header file of UIMoreNavigationController you will notice it has a variable
UINavigationController* _originalNavigationController;
which is accualy the originalUINavigationController
that you created and that you want to access. Unfortunetly you cant sinceUIMoreNavigationController
is private.Workaround (ugly)
Pass the reference of your NavigationController to its children when you push them on it's stack.