Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CorporateFelon

macrumors regular
Original poster
Oct 26, 2007
177
0
Boston, MA
So I have an app that looks similar to the Youtube app. A Table view and in each cell an Image with text describing the record.

However, after launching the app I've received complaints about the performance when scrolling through the list in the Table View. I hadn't seem this during testing or development so I didn't know it existed, but that's my fault for not properly testing as much as I could.

Any way, to populate the images I am pulling them from the internet using the follow code with in the cellForRowAtIndexPath method

Code:
UIImage *uiThumbImage;

if(itemobj.image != nil)
{
	NSURL *imageUrl = [NSURL URLWithString: itemobj.image];
	NSData *imageData = [NSData dataWithContentsOfURL: imageUrl];
	uiThumbImage = [[UIImage alloc] initWithData:imageData];
}
else
{
	uiThumbImage = [UIImage imageName: @"DefaultThumb.png"];
}

[[cell uiImage] setImage:uiThumbImage];

I am recycling the TableViewCell with dequeueReusableCellWithIdentifier so my understanding is that the code will run every time the cell is coming back on screen. However now that I think about it here is my question. Will the program try to dl the images every time the cell is displayed again? Or are they cached some where? Even though the images are small I think if they have to be downloaded again every time the user scrolls through the records that may be the cause of my performance issues.

If this is the case where they images are being redownloaded every time instead of being cached, what would be an efficient way to go about caching that images?
 
It'll be redownloaded everytime the row is visible. You should cached the image instead.
 
Something like this :

Code:
cellForRowAtIndexPath  :
      if (images[row] == nil)
      {
           download the image and put it inside images[row];
      }

      [[cell uiImage] setImage:images[row]];
 
You can't use a synchronous method for getting the images. What happens if the net is slow, or unavailable?

You need to use the NSURLConnection asynchronous method for downloading the images. You need to cache them locally, either in memory or on disk. You need to show a blank image if the real image hasn't yet been downloaded and then update the table when the real image becomes available.

Also, look at this

http://developer.apple.com/iphone/library/samplecode/LazyTableImages/index.html
 
You can't use a synchronous method for getting the images. What happens if the net is slow, or unavailable?

You need to use the NSURLConnection asynchronous method for downloading the images. You need to cache them locally, either in memory or on disk. You need to show a blank image if the real image hasn't yet been downloaded and then update the table when the real image becomes available.

Also, look at this

http://developer.apple.com/iphone/library/samplecode/LazyTableImages/index.html

Thanks for the link to an example, that was a perfect guide for fixing my issues.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.