Load All TabBar Views

前端 未结 7 2064
独厮守ぢ
独厮守ぢ 2020-12-05 13:59

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

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-05 14:33

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

提交回复
热议问题