Load All TabBar Views

Laurent May picture Laurent May · Feb 8, 2012 · Viewed 11.2k times · Source

I have a tabbar controller as the root view controller. I would like to pre-load the views of tab [1,2,3] (tab 0 loads as the first tab automatically).

I essentially would like the code in viewdidload to run before the user taps on the tab.

Thanks

Answer

Joel Kravets picture Joel Kravets · Feb 9, 2012

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)];