我正在尝试将图像设置为 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;
}