If you are using iOS 5, you can do something like this:
- (void) processViewController: (UIViewController *) viewController { //do something with viewcontroller here NSLog(@"I'm viewcontroller %@", viewController); for ( UIViewController *childVC in viewController.childViewControllers ) { [self processViewController:childVC]; } }
and start all the fun:
[self processViewController:myRootViewController]; //would be the tabbarcontroller in your case
Edit: I'm not sure what you want to achieve here, but this code is for traversing an entire tree.
Edit 2:
For iOS 4, try something like this:
- (void) processViewController: (UIViewController *) viewController { //do something with viewcontroller here NSLog(@"I'm viewcontroller %@", viewController); if ( [viewController isKindOfClass:[UITabBarController class]] ) { for ( UIViewController *childVC in ((UITabBarController *)viewController).viewControllers ) { [self processViewController:childVC]; } } else if ( [viewController isKindOfClass:[UINavigationController class]] ) { for ( UIViewController *childVC in ((UINavigationController *)viewController).viewControllers ) { [self processViewController:childVC]; } } }
Note. You will need to add any custom view manager that has subviewcontrollers. If you have any ... The root view controller gets it again.
huesforalice
source share