Nitin
Nitin

Reputation: 11

Lazy loading thumbnail images

I am trying to lazily load a dynamic thumbnail view.

I have to put images in thumbnail view one by one and until images are not available I have to display temporary image like placeholder. Any guidelines please?

Upvotes: 1

Views: 1813

Answers (2)

Duncan Babbage
Duncan Babbage

Reputation: 20187

See the accepted answer in this thread. You wouldn't need the last-in first-out stack, but it shows how to load images asynchronously using grand central dispatch, which is quite straightforward. You don't need to think about complicated thread management. :)

Upvotes: 1

Srikar Appalaraju
Srikar Appalaraju

Reputation: 73608

You could go about like this -

  1. Create a UIImageView with a default placeholder image.
  2. Fetch your image in a background thread. You want to do it like this because, fetching image in the main UI thread blocks it till the image is fetched, which severely hampers UI responsiveness. There are several libraries available which do this for you. They even cache the images. SDWebImage is great!
  3. See if you get a valid HTTP 200 response back i.e. a valid image. If yes, then replace the new image with placeholder image. Else let the placeholder image be.

Hope this helps...

Upvotes: 0

Related Questions