I’m using the setImageWithURL to lazily load images into my tableview cells but there is a problem. It loads the images fine but there seems to be a refresh problem on the device where the images only show when you scroll them out of the view and back in again.
It works perfectly in the simulator. The device is running iOS 5.1.1 on a iPhone 4S
This table is displayed in a UINavigation controller and as the images are cached I expect the images to appear pretty quickly when I revisit the screen. They do, but the show up at half their original size.
The images are 60×30 in size.
Is this an issue with loading images into a retina screen that they are half the size and what would cause this refresh problem?
Code snippet below…
- (UITableViewCell *)tableView:(UITableView *)tableview cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
...
[cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"transparent_shade"]];
...
return cell;
}
Thanks in advance for any insights
I would suggest loading/preparing the images before the
cellForRowAtIndexPathmethod. The reason you are seeing the images after scrolling is because the images were previously downloading at the time this method was called, hence the files were not yet available.Make a
NSMutableArrayinside your view’sviewWillAppearmethod (override it if non-existent) for instance, and put all the images inside the array. Then, in thecellForRowAtIndexPathsimply get the images from the array and assign them as needed; they should be displayed on demand, without delays.Let us know how this works for you.