Lazy load images in UITableViewCell

两盒软妹~` 提交于 2019-11-26 15:06:13

Loading the images on a background thread is still a good idea. If you didn't want to reload them each time, I'd suggest setting up an NSMutableDictionary and storing the images in there. You could use some unique identifier, like the row ID or even the name of the image, as the key for each image.

When loading a cell, you'd send an objectForKey: message to the NSMutableDictionary to retrieve the image for that particular cell (based on your unique key for it). If it returns nil, that means that the image is missing from the cache and you need your background image loading thread to go retrieve it. Otherwise, you will get back the appropriate image for your table cell to display. On a memory warning, you could clear out this cache of images with no adverse effects (aside from forcing them to be reloaded again on demand).

I have just successfully tackled the same problem by using a custom NSOperation to load the images in a queing fasion and stored them into a static NSMutableDictionary as a cache. Below is a link to the basis of the code I used to solve the problem.

Loading remote images for UITableViewCell

Best to read all the threads in the forum to help you understand what's actually going on.

magma

lostInTransit,

I am having a similar problem and while exploring the many different possible solutions I found this blog post:

davidgolightly.blogspot.com/2009/02/asynchronous-image-caching-with-iphone.html

I would also suggest that you download the URLCache sample from the apple developer website:

developer.apple.com/iphone/prerelease/library/samplecode/URLCache/

And here is another post on the problem:

www.markj.net/iphone-asynchronous-table-image/

I'd love you to share your findings as well.

Lazy loading is like synchronous type request.. means wait for respond

ego image button is solution for that..

ego image button is asynchronous type request..don't wait for respond..just display data at a time....

you can download folder from github....

add to your project...

in xib..at image view ,change class to ego image button...

make object of it in m file...

you can use.....

For those who are interested, and are lazy like me, I would like to suggest an open source (MIT license) implementation of lazy/cached network of UIImageView images: SDWebImage

UITableView with image caching and resizing/setting in background thread:

http://blog.slaunchaman.com/2011/08/12/gcd-example-updated-now-with-more-speed/

This is Tutorial about NSOperation with example that show how to Lazy load images in UITableViewCell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!