为什么 SDWebImage 加载后不在单元格中显示图像? [英] Why SDWebImage do not show image in a cell after load?

查看:33
本文介绍了为什么 SDWebImage 加载后不在单元格中显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using SDWebImage. In my table, each row has image and a label.

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

As you can see, image cannot be seen.

但是当我回到父视图控制器并再次来到这里时,它们会显示出来.

But when I go back to parent view controller, and come here again, they are shown.

我使用的代码是:

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

那么,我错在哪里?

推荐答案

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

Answer: get/make a transparent png, and use it as your placeholder image.

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

Actually, it is not a bug with SDWebImage, but rather it's the nature of how UITableView works. SetImageWithURL, is an asynch process. So when your tableView delegate/datasource methods are called, the image isn't downloaded yet, so cellForRow doesn't have an image to display.

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

The reason it works when you navigate elsewhere then back, is because by then the image has been downloaded, and cellForRow gets called again, this time with an image to display.

这篇关于为什么 SDWebImage 加载后不在单元格中显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆