Usually, to see example code that looks at the hierarchy of views from root to get a pointer to a specific view controller, for example:
UITabBarController *tabBC = (UITabBarController *)self.window.rootViewController;
UINavigationController *navC = [tabBarController viewControllers][0];
MyCustomTableViewController *myVC = [navigationController viewControllers][0];
It is hopelessly fragile, breaking every time a storyboard adjustment is revised. What seems necessary is the UIViewController method, for example:
-(NSArray*) childVCsOfClass:(Class)targetClass;
or perhaps:
-(NSArray*) childVCsPassingTest:
I wrote this departure in order to perform a simpler case of finding the first instance, but still suspect that I'm missing something obvious:
UIViewController* FirstChildViewControllerMatchingClass(UIViewController* rootVC, Class targetClass) {
UIViewController *thisController = rootVC;
UIViewController* foundInstance = nil;
if([thisController isKindOfClass:targetClass]) {
return thisController;
}
if([thisController respondsToSelector: @selector(viewControllers)]) {
for(id vc in [(id)thisController viewControllers] ) {
foundInstance = FirstChildViewControllerMatchingClass(vc,targetClass);
if(foundInstance) {
return foundInstance;
}
}
}
if(thisController.childViewControllers) {
for(UIViewController* kids in thisController.childViewControllers ) {
foundInstance = FirstChildViewControllerMatchingClass(kids,targetClass);
if(foundInstance) {
return foundInstance;
}
}
}
return nil;
}
, , , Apple ( - ) , . ( OTOH ;)