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?
I think this example will help you.. http://kosmaczewski.net/2009/03/08/asynchronous-loading-of-images-in-a-uitableview/
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:]
.
- You should go with array of image link instead of the image.
- You should load image asynchronously so that it will improve performance of creation of the UITableviewCell.
- Verify that you are using dequeueReusableCellWithIdentifier, it will give you the smoother scrolling.
精彩评论