ios - 为什么 SDWebImage 在加载后不在单元格中显示图像?

标签 ios uitableview sdwebimage

我正在使用 SDWebImage。在我的表格中,每一行都有图像和标签。

enter image description here

如您所见,无法看到图像。

但是当我返回到父 View Controller 并再次来到这里时,它们会显示出来。

enter image description here

我使用的代码是:

[cell.imageView setImageWithURL:[NSURL URLWithString:serie.image] placeholderImage:[UIImage imageNamed:@"placeholder.png"]  options:SDWebImageRefreshCached];

那么,我哪里错了?

最佳答案

答案:获取/制作一个透明的 png,并将其用作您的占位符图像。

实际上,这不是 SDWebImage 的错误,而是 UITableView 工作方式的本质。 SetImageWithURL,是一个异步进程。因此,当调用 tableView 委托(delegate)/数据源方法时,图像尚未下载,因此 cellForRow 没有要显示的图像。

当您导航到别处然后返回时它起作用的原因是因为那时图像已经下载,并且 cellForRow 被再次调用,这次带有要显示的图像。

关于ios - 为什么 SDWebImage 在加载后不在单元格中显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18386979/

相关文章:

ios - 如何知道 Root View Controller View 层次结构已完成加载

ios - 当 Image 的数组响应为 null 时,SDWebImage 会导致 TableView 崩溃

ios - 如何在使用 SDWebImage 加载图像时传递 Authtoken

ios - SDWebImage - 如何延长下载超时

ios - 如何快速转换java代码?

ios - 如何使用 xcassets 中的图像?

ios - UITableView 不显示滚动

ios - UISplitViewController : Can DetailViewController load data from MasterVIewController without segueing back?

iphone - UITableViewCell 和检查点击的问题

ios - 如何按部分从 Api 接收数据?