所以我有代码在前台更改 tableView 的单元格图像(在后台下载图像后):
dispatch_queue_t background = dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(background, ^{
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://whatever.jpg"]]];
dispatch_queue_t foreground = dispatch_get_main_queue();
dispatch_async(foreground, ^{
cell.imageView.image = image;
});
});
现在我知道代码工作正常,因为它会在我委托(delegate)离开 tableview 并返回时加载。如果我在设置 imageView 的同时将 cell.textLabel.text 设置为某些内容,它也会工作(自动加载),但出于某种原因,仅尝试使用 block 更改单元格图像是行不通的。
如果它们不在 block 中,它也会起作用,但我不想这样做,因为会延迟。
感谢所有帮助:)
最佳答案
尝试添加 [cell.imageView setNeedsLayout:YES]
,除此之外我看不出你的代码是如何工作的,我的一个应用程序中有完全相同的代码而且它工作正常。
关于ios - Cell.imageView.image 更改后不会自动加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23408466/