Siddharthan
Siddharthan

Reputation: 141

NSURL image loading slows down the app opening time - iOS

I have a scrollable view where the UIImageView objects are added dynamically based on the number of files. The UIImageView loads its image from an url. So for example if I have around 50 images to be loaded, how can I not let the loading stop the app from opening. This image is loaded on the initial view controller. I would like to add an activity indicator as a subview to the UIImageView object. and then it can load the images. However the app waits until all the images are loaded and then it opens. Hence i see a black screen for almost a minute. Any suggestion would be greatly appreciated

Upvotes: 0

Views: 277

Answers (2)

Hermann Klecker
Hermann Klecker

Reputation: 14068

You can look into asyncronously loading the images and let iOS cope with the threads.

Have a look at this tutorial. http://www.markj.net/iphone-asynchronous-table-image/ It shows how to add dynamically loaded images to a table. However, the principle behind that will work with your scroll view as well.

The principle is to subclass UIImage and add the methods for async load from URL and receiving data and finally displaying the image.

Upvotes: 1

saadnib
saadnib

Reputation: 11145

You can use secondary thread for that. Use NSThread to start a secondary thread. https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsthread_Class/Reference/Reference.html

Upvotes: 1

Related Questions