I've a UITableView
and each UITableViewCell
displays a unique UIImage
which is fetched from internet. As we scroll the UITableView
, cells are recreated and tableView: cellForRowAtIndexPath:
gets called every time to configure cells. So it loads UIImages
again and again from internet and scrolling is not smooth.
The solution I found for myself right now is to create NSMutableArray
of all those UIImages
on ViewDidLoad
then load images into UITableViewCells
from that NSMutableArray
which is for sure giving me smooth scrolling.
My concern with my own solution is that when I keep all UIImages
in NSMutableArray
and those all objects are kept in memory for as long as application runs, I am most probably making inefficient use of memory.
Is there a better, more efficient way to do this which gives me smooth scrolling as well as best memory usage?
Cache the downloaded images on the filesystem. When loading a cell, first ensure that a cached copy of the associated image is available, then load it using [UIImage imageWithContentsOfFile:]
.
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.