Kingfisher: TableView Cell quick datasource change

Created on 15 Oct 2015  路  6Comments  路  Source: onevcat/Kingfisher

Hi I use kingfisher in a tableview cell. Id I quickly switch the datasource and some image are wrong. I guess it's because the NSURL get wasn't finished before the the datasource switch and therefore sets the image on the wrong cell.

as you can see here some images for persons are actually organisations

kingfisher issue
here is how I set the image on the cell in the layoutSubviews of the UITableViewCell

if let newURL = mainProfile?.imageURL {
            self.cellImage.kf_setImageWithURL(NSURL(string: newURL)!, placeholderImage: UIImage(named: "no photo"))
        } else {
            self.cellImage.image = UIImage(named: "no photo")
        }

Most helpful comment

Kingfisher will link your url to the image when using kf_setImageWithURL methods. When the image loading finished, there is a check on whether the url of downloaded image matches the target url. The image will be set only when the two urls match. So I guess it is probably not a Kingfisher issue.

The reason might be your cells of organization are reused in the persons tab, without cellImage updated (your layoutSubviews not get called in these two cells).

All 6 comments

Kingfisher will link your url to the image when using kf_setImageWithURL methods. When the image loading finished, there is a check on whether the url of downloaded image matches the target url. The image will be set only when the two urls match. So I guess it is probably not a Kingfisher issue.

The reason might be your cells of organization are reused in the persons tab, without cellImage updated (your layoutSubviews not get called in these two cells).

Strange I force the layoutSubviews in the cellForIndexpath. This only happens when the datasource changes while the view is scrolling

I guess I know why.

self.cellImage.image = UIImage(named: "no photo") it will not set the under-hood url for Kingfisher.

Would you please try to change this line to:

self.cellImage.kf_setImageWithURL(NSURL(string: "")!, placeholderImage: UIImage(named: "no photo"))

and have a try to see the result?

I see! makes sense I will try it. I killed the scroll before switching the datasource and it seems like it resolved the problem. But this suggestion makes sense

@wieseljonas Hi. :)
How's going on this?

@onevcat Sorry! It's working to perfection! thanks a lot

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sindresorhus picture sindresorhus  路  3Comments

joebenton picture joebenton  路  4Comments

rainerjungwirth picture rainerjungwirth  路  4Comments

freak4pc picture freak4pc  路  3Comments

wudijimao picture wudijimao  路  3Comments