Load All TabBar Views
If you take your view initialization code and move it into loadView instead of viewDidLoad you can force each of the UIViewControllers that are part of your UITabBarController to be loaded by simply calling viewController.view. This happens because a UIViewController will create the view object via the loadView function when asked for it.
for(UIViewController * viewController in tabBarController.viewControllers){ viewController.view;}
or more simply
[tabBarController.viewControllers makeObjectsPerformSelector:@selector(view)];
In iOS 8, I created a subclass of UITabViewController named TSMainBarViewController. In the function viewDidLoad
of TSMainBarViewController, I just added this code:
for(UINavigationController * viewController in self.viewControllers){ [[viewController.viewControllers firstObject] view];}
Then all the viewControllers (root viewController of UINavigationController) will load . All my viewControllers are created in the StoryBoard. Do not implement the function loadView
in the UIViewController.
Swift 3 code from EligyD:
for viewController in self.viewControllers! { _ = viewController.view}
To handle tab controllers which might or might not have navigation controllers:
viewControllers?.forEach { if let navController = $0 as? UINavigationController { navController.topViewController?.view } else { $0.view.description }}