0

我正在尝试将图像设置为 UITableViewCell 但除非滚动它才会显示。

如果重复,我深表歉意。但我尝试了 setNeedsDiplay、reloadRowsinIndexPAth 和所有其他重新加载方法。我正在使用 SDWebImageCache 下载图像和RayWenderlich 的示例来创建水平 Tableviewcells。我正在粘贴我的代码供您参考。

- (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;
}
4

2 回答 2

1

与 UI 相关的所有内容都需要在主线程内处理,因此将

[imageView setImageWithURL:imageURL];

此代码位于 dispatch_get_main_queue() 块内部。

于 2013-03-14T00:48:48.180 回答
0

回答我自己的问题。

我摆脱了中间的 UIImageview。将图像直接设置为缩略图就可以了。

于 2013-03-28T18:13:49.217 回答