ios - Cell.imageView.image 更改后不会自动加载

标签 ios objective-c uitableview

所以我有代码在前台更改 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/

相关文章:

ios - 将 NSLayoutConstraints 与 CALayer 支持的 View 结合使用无法正确设置动画

ios - IOS 6/7 中的框布局?

WebView 滑动时 iOS 应用程序崩溃

ios - UITableView具有白色背景而不是清晰的背景

ios - setSeparatorStyle 仅在 1 个部分

ios - 运行 Storyboard 项目时,符合 Monotouch 键值编码标准的崩溃

ios - UIScrollView canCancelContentTouches 不禁用滚动

iphone - 如何拉伸(stretch) UIImage 以适合文本?

iphone - 七层信息层次 - UITableView - iPhone

ios - 在两个 View Controller 之间传输时将 NSArray 存储到文件