Note that there are some explanatory texts on larger screens.

plurals
  1. POCached UIImages fetching performance in UITableView
    primarykey
    data
    text
    <p>I've been using @atebits's <a href="http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/" rel="nofollow noreferrer">ABTableViewCell</a> for a while. For those who are unfamiliar with it, basically it makes tableview scrolling <em>much</em> faster by drawing all the labels and images, instead of allocating UIKit objects (such as UILabels, UIImageView, etc).</p> <p>Now, I have pretty big <code>UITableViews</code> and in each cell, there's a small (32x32) user image and a medium (75x75) photo thumbnail. The drawing really helps on making this tableview scroll fast, but I'm still trying to figure what's the best way to fetch these images that are to be drawn inside the cells.</p> <p>I've looked at Apple's <a href="http://developer.apple.com/iphone/library/samplecode/LazyTableImages/Introduction/Intro.html" rel="nofollow noreferrer">LazyTableView</a> example, but I'm still not sure what's the best way to do this. All I know is the less code/allocation you have in <code>cellForRowAtIndexPath:</code>, the better it is.</p> <p>So my images either get downloaded from the server or get retrieved from my CoreDataHelper. My question is: <strong>which of the following methods is better to retrieve the cached images</strong>?</p> <ol> <li><p>Use <code>NSFetchRequest</code> in <code>cellForRowAtIndexPath:</code> to fetch the cached image (therefore allocating NSFetchRequest instances as the tableview is scrolling).</p></li> <li><p>Retain all the cached images from the start within the tableView's datasource, that way I can just fetch them off the (already allocated array in <code>viewDidLoad:</code>) datasource in my <code>UITableViewController</code>. This method clearly takes up more memory since it allocates a bunch of small images, but I'm guessing the scrolling would end up being much smoother.</p></li> </ol> <p>Can anyone enlight me on this? </p> <p>(By the way, I want the images to appear <em>as the tableview is scrolling</em>. Waiting for it to stop scrolling to load the images is not an option).</p> <p><br> <strong>EDIT: loading images from disk</strong></p> <p>Following the provided answers, I'm now trying to load the images directly from disk (after they get saved, obviously) using the image local path, which is part of the tableview datasource. Here's the code inside the <code>cellForRowAtIndexPath:</code> method:</p> <pre><code>NSData *imageData = [NSData dataWithContentsOfFile:imageLocalPath]; UIImage *userImage = [UIImage imageWithData:imageData]; cell.avatarImage = userImage; </code></pre> <p>It's still not butter smooth (there's a small lag every time a new cell appears (everytime <code>cellForRowAtIndexPath</code>: is called) Should I be making this call asynchronously? Or is disk reading quick enough and is definitely not the issue here?</p> <p><br> <strong>EDIT: More details</strong></p> <p><strong>1. Where are you getting the imageLocalPath?</strong></p> <p>The image url is part of my dataSource, which is an NSArray allocated in viewDidLoad (cached into CoreData but that shouldn't affect scrolling). The app documents directory path is also retained in viewDidLoad, so the whole filepath is computed in cellForRowAtIndexPath using</p> <pre><code>NSArray *urlArray = [picURLString componentsSeparatedByString: @"/"]; NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsPath, [urlArray lastObject]; </code></pre> <p><strong>2. What happens when you run this through shark?</strong></p> <p>I never used Shark before, tried to use it and apparently iOS 4 no longer supports it. Can you confirm this? When I hit the "Start" button, nothing happens.</p> <p><strong>3. What FPS are you getting in Instruments on the device?</strong></p> <p>I'm getting between 25 and 30fps, but it really doesn't look this smooth on the actual screen. Not sure if this means something. I feel like I'm getting 10-15fps. Again, scrolling is smooth between the cells, it's just when the tableview hits a new cell that there's a slight lag (so fast scrolling = many of those small lags every second).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload