My code downloads images asynchronously using InternetImage in the tableview: cellForRowAtIndexPath:
method by initializing a IntentImage with initWithURL and calling downloadImage. This code runs perfectly after scrolling down to a new cell UITableViewCell in the UITableView, but not before, even though the URL is correct in both cases. None of InternetImage's NSURLConnection delegate methods are called to notify me about success or failure of the connection, as they should be. Calling reloadData:
, setNeedsDisplay:
, and setNeedsLayout:
do nothing since the image fails to download.
Here is the code from my subclass of UiTableViewController:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Object *object = (Object *)[self.array objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"] autorelease];
}
cell.textLabel.text = object.attribute;
if (object.image == nil && object != nil) {
NSString *URLString = [[MyAppDelegate imageURLFromLink:(object.link) withExtension:@".jpg"]absoluteString];
InternetImage *asynchImage = [[InternetImage alloc] initWithUrl:URLString object:object];
[asynchImage downloadImage:self];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if (object.image != nil && object.thumbnailImage == nil) {
UIImage *image= (UIImage *) object.image;
UIImage *thumbnail = [image _imageScaledToSize:CGSizeMake(75.0, 50.0) interpolationQuality:20];
object.thumbnailImage = thumbnail;
}
cell.imageView.image = object.thumbnailImage;
return cell;
}