简体   繁体   中英

iPhone - UITableView reload on scrolling

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

  1. You should go with array of image link instead of the image.
  2. You should load image asynchronously so that it will improve performance of creation of the UITableviewCell.
  3. Verify that you are using dequeueReusableCellWithIdentifier , it will give you the smoother scrolling.

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