Lazy load images in UITableViewCell

2019-01-03 12:30发布

I have some 50 custom cells in my UITableView. I want to display an image and a label in the cells where I get the images from URLs.

I want to do a lazy load of images so the UI does not freeze up while the images are being loaded. I tried getting the images in separate threads but I have to load each image every time a cell becomes visible again (Otherwise reuse of cells shows old images)

Apps like Facebook load images only for cells currently visible and once the images are loaded, they are not loaded again. Can someone please tell me how to duplicate this behavior.

Thanks.

Edit
Trying to cache images in an NSMutableDictionary object creates problems when the user scrolls fast. I am getting images only when scrolling completely stops and clearing out the cache on memory warning. But the app invariably gets a memory warning (due to size of images being cached) and clears the cache before reloading. If scrolling is very fast, it crashes.

Any other suggestions are welcome

7条回答
爷、活的狠高调
2楼-- · 2019-01-03 13:25

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

查看更多
登录 后发表回答