1

There are four tabs in my app. When the user first opens the app, he will see the first tab's view controller. At this point, I want to load all the other tabs' content, so when the user opens other tabs he will see the content instantly.

enter image description here

I know it's possible in Android. Is it possible in iOS?

EDIT:

I tried to prepare a viewcontroller by invoking [myViewController view]; inside AppDelegate but when I clicked the tab that opens the viewController, it seems to load again with a new view.

Related: Force viewDidLoad to fire on iOS

Community
  • 1
  • 1
Maximus S
  • 10,759
  • 19
  • 75
  • 154
  • Move your data logic to initializer methods such as initWithCoder of ViewController . This way when ViewControllers get initialized by Tabbarcontroller you will have your data ready. Make sure to perform heavy data logic in background thread. – Puneet Sharma Sep 05 '15 at 10:56
  • @Puneet Thanks.. I just tried it and it seems I don't get that much of performance boost. All the tabs have their own webView, and I loaded a webview in `initWithCoder`, and called `addSubview` in `viewWillAppear`. I assumed `addSubview` can't be called at `initWithCoder` stage. When's the fastest time that I can load a webview for each tab? – Maximus S Sep 05 '15 at 11:24
  • Webview starts loading only when it is added to subview which you can do earliest in viewDidLoad. Try using webview's startLoading method in init and see if it gets loaded before adding to subview. – Puneet Sharma Sep 05 '15 at 11:33
  • @Puneet I am looking at https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebView_Class/#//apple_ref/occ/instm/UIWebView/stopLoading and to initiate loading, I must call `loadRequest` which I am already doing. Hm – Maximus S Sep 05 '15 at 11:37

3 Answers3

2

The view of your viewController is lazily loaded (meaning automatically loaded when needed). If you want to load it in advance, just call the getter once.

[myViewController view];
deadbeef
  • 5,409
  • 2
  • 17
  • 47
-1

Yes, it is possible. You should load your data in init methods or viewDidLoad method of your ViewController. Thus, data of other tabs will be loaded.

Candost
  • 1,029
  • 1
  • 12
  • 28
  • But viewDidLoad will get called only when tabbarcontroller will push view on screen. I dont think OP wants to load data at that time. – Puneet Sharma Sep 05 '15 at 11:10
  • It depends on conditions. I don't know what Maximus S wants and this is just a way to do. – Candost Sep 05 '15 at 11:16
-1

You can create a Singleton class for your all tabs data/content like 'DataManager' and load all data when first view appears.

http://www.galloway.me.uk/tutorials/singleton-classes/

Muhammad Awais
  • 340
  • 3
  • 15