Reputation: 471
There is a scenario where I'm uploading images, PDF and YouTube URL to the server and after completion, these items are getting displayed in UICollectionView
. The image is displayed as it is, for PDF an icon is there and for video, it's thumbnail. If I upload the image first then pdf and then YouTube URL, then in collectionView, the cell with pdf icon is replaced by the image. I'm using Kingfisher for downloading and caching images from the web.
Here is my collectionViewCell code.
override func prepareForReuse() {
self.imageView.image = nil
}
func configure(doc: GenericSubmissionDoc) {
switch doc.type {
case .document:
self.imageView.image = UIImage(named: "Pdf-icon")
case .image:
self.imageView.setImageFromUrl(urlString: doc.url)
case .video:
self.imageView.contentMode = .scaleAspectFit
guard let thumbnailLink = doc.videoThumbnailUrl else {
self.imageView.image = UIImage(named: "youtube")
return
}
self.imageView.setImageFromUrl(urlString: thumbnailLink, placeHolder: UIImage(named: "Node-Placeholder"))
}
}
Upvotes: 0
Views: 145
Reputation: 8855
I guess you need to cancel the image download in prepareForReuse
- just setting the image to nil
will not do that.
Consider the following scenario:
image
or video
cell, image download is triggereddocument
cell and you set the Pdf-icon
image (the download from before is still running!)Upvotes: 1