0

I am trying to set an image to the UITAbleViewCell but it does not show up untill unless scrolled.

I apologize if its repetitive. But I've tried setNeedsDiplay, reloadRowsinIndexPAth, and all other reload methods. I am using SDWebImageCache to download the image and RayWenderlich's example to create horizontal Tableviewcells. I am pasting my code for your reference.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ArticleCell";
__block ArticleCell_iPad *cell = (ArticleCell_iPad *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    cell = [[ArticleCell_iPad alloc] initWithFrame:CGRectMake(0, 0, kCellWidth_iPad, kCellHeight_iPad)];
}
if ([self.articles count] == 0) {
    return cell;
}
__block Offer *offer = [self.articles objectAtIndex:indexPath.row];
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(concurrentQueue, ^{
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 201, 201)];
    NSURL *imageURL = [NSURL URLWithString: [NSString stringWithFormat:@"%@", offer.image.url]];
    [imageView setImageWithURL:imageURL];
    dispatch_async(dispatch_get_main_queue(), ^{
        [cell.thumbnail setImage:imageView.image];
        cell.titleLabel.text = offer.title;
        cell.priceLabel.text = [NSString stringWithFormat:@"$%@", offer.regularprice];
    });
});
dispatch_release(concurrentQueue);
cell.selectionStyle = UITableViewCellSelectionStyleNone;

return cell;
}
shyamsundar1988
  • 529
  • 4
  • 14

2 Answers2

1

Everything related to UI need to be processed inside of main thread so place the

[imageView setImageWithURL:imageURL];

this code to inside of the dispatch_get_main_queue() block.

andykkt
  • 1,696
  • 16
  • 23
  • Hi Andy, Thanks for your response. I've tried that too. Still no good. SDWebImageCache said in one of their blogs to use a placeholder image. Even that didnt work in this case. – shyamsundar1988 Mar 14 '13 at 17:43
0

Answering my own question.

I got rid of the intermediate UIImageview. Setting the image directly to the thumbnail did the trick.

shyamsundar1988
  • 529
  • 4
  • 14