简体   繁体   中英

Why SDWebImage do not show image in a cell after load?

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.

在此输入图像描述

The code I am using is:

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

So, where I am wrong?

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM