4

I have a tab bar controller with 4 separate views. When I navigate from the first view to the second view, it takes some time to load up the second view.

What I want to do is, be able to load and initialise all of my tab bar views during my splash screen. That way, when the user navigates between the tab views, there is no wait time.

how do I manually initialise my individual tab bar views in my app delegate?

Sanoj Kashyap
  • 5,020
  • 4
  • 49
  • 75
codenoobie
  • 41
  • 1
  • 2
  • What is it that needs to be loaded into various views? I don't think that you get much processor time during splash screen, and if you did wouldn't your loading just prolong the splash screen? – westsider Jan 07 '11 at 01:03
  • Possible duplicate of [Load All TabBar Views](http://stackoverflow.com/questions/9202737/load-all-tabbar-views) – Sahil Kapoor Jul 20 '16 at 06:57
  • this one might help... a little dated, but some updates for swift 3 - https://stackoverflow.com/questions/9202737/load-all-tabbar-views – Matthew Ferguson Dec 08 '17 at 18:21

2 Answers2

3

To load a tab view programmatically, e.g. in application:didFinishLaunchingWithOptions: you can:

// load the third one, for instance
thirdNavController = [tabBarController.viewControllers objectAtIndex:2];
[thirdNavController.topViewController loadView];
Jan Soltis
  • 4,320
  • 2
  • 25
  • 23
  • 1
    [Documentation](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instm/UIViewController/loadView) states "You should never call [loadView] directly". However, "If you access [the view property] and its value is currently nil, the view controller automatically calls the loadView method" as per [this answer](http://stackoverflow.com/a/9203007/142845). – Will Jan 19 '15 at 19:06
2

I think accessing the view property of each of your controllers will cause it to be loaded (lazy loading). Though I don't think you can have an absolute guarantee it won't get unloaded before you use it if memory is tight.

Andy J Buchanan
  • 1,952
  • 14
  • 13