2

I am currently developing a Swift application with a "LoginViewController". When the user is authentified, the application goes on a UITabBarController with 4 tabs.

In the fourth tab, I have to load an image from the internet in an UIImageView. I want that image to be loaded when I arrive on the first tab because there is a delay to load this image when I click on the fourth tab.

The code to load this image is in the viewDidLoad() of the fourth ViewController associated to my fourth tab. Is there any way to load this image before I go to the fourth tab ?

Maybe in the viewDidLoad of the first tab ? or in the viewDidLoad of the UITabBarViewController ?

I've already checked this link but can't make it work : How to load all views in UITabBarController?

Community
  • 1
  • 1

2 Answers2

2

I think the best way is to isolate the code that downloads the image somewehere else, let say DownloadManager class as a class method class func downloadFourthTabImage and then you call this method when the user finished login or in the first thing loads in the tab view controller.

The same applies to all data you need to load for the other viewcontrollers.

Note Make sure to download the image in background queue to prevent freezing your UI.

Ismail
  • 2,778
  • 2
  • 24
  • 39
1

It is better to download the image on Service/Network layer instead of UI Layer, and when you will land on 4th tab, you can display image from imageWithContentOfFile method.

Ankit Thakur
  • 4,739
  • 1
  • 19
  • 35