Load All TabBar Views

前端 未结 7 2061
独厮守ぢ
独厮守ぢ 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:23

    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
    }
    

提交回复
热议问题