简体   繁体   中英

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?

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. :)

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 ie a valid image. If yes, then replace the new image with placeholder image. Else let the placeholder image be.

Hope this helps...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM