I'm curious if there is a legitimate API with which to obtain the view controllers that are children of a UIMoreListController
? (The UIMoreListController is the child at the top of the UIMoreNavigationController's view stack. The UIMoreNavigationController is the object pointed to by the moreNavigationController
property of a UITabBarController
.)
In other words, if I have a UITabBarController and I set an array of six view controllers on it, the view hierarchy will actually look like this (it's actually a hierarchy of views, not view controllers, but using these identifiers make more sense):
+ UITabBarController <-- has five tabs
|--- view controller <-- these are my own view controllers
|--- view controller
|--- view controller
|--- view controller
|--+ UIMoreNavigationController <-- root view controller of fifth tab
|--+ UIMoreListController <-- table-based view shown on fifth tab
|--- view controller <-- these are my own view controllers
|--- view controller
One way to do this is to simply get the view controllers from the UITabBarController's viewControllers
property, check to see if there are more than 5, and return all the view controllers from index 5 to N - 1
if there are more than 5. (If there are less than 5, then no view controllers will be children of the UIMoreNavigationController.)
However, I'd like to avoid hardcoding any assumptions about the number of view controllers that a UITabBarController will display before listing the remaining controllers in the moreNavigationController
. Apple could change that number in the future. But I can't find any API on either UITabBarController or on UINavigationController with which to access these children, and UIMoreNavigationController is not a public class so I can't rely on any methods exposed on that class.
I still haven't found a real API for accomplishing this. However, it can be done without making assumptions based on checking the
UIUserInterfaceIdiom
and assuming a max of 5 or 8 tabs. It's kind of ugly, kind of simple:UITabBarController.tabBar.items
will include the tab bar item for themoreNavigationController
, if there is such a tab bar item.moreNavigationController
.moreNavigationController
) and that's the index of the first child of themoreNavigationController
withinUITabBarController.viewControllers
.Or, in code: