iOS/이슈
[iOS Issue] UICollectionView cell에서 SDWebImage 사용 시 잘못된 이미지 로드되는 이슈
Sky Titan
2021. 1. 21. 10:26
728x90
Cell being populated with wrong images · Issue #1024 · SDWebImage/SDWebImage
Hi, I'm currently using this code to set-up my images: [cell.coverImage sd_setImageWithURL:[self.dataInJSONModel.Content[indexPath.row] CoverImage] placeholderImage:[UIImage imageNamed:@"i...
github.com
UICollectionView cell에서 SDWebImage를 사용할 때 cell을 scroll할 때마다 잘못된 이미지들이 로드되어 보이는 현상이 발생한다. Cell Class에 prepareForReuse메서드를 오버라이드 해서 imageView의 image를 초기화하는 작업을 진행하니 해결이 되었다.
통상적으로는 image = nil로 하지만 나는 default 이미지인 placeholder이미지로 초기화하게 했다.
import UIKit
class TestCell: UICollectionViewCell {
@IBOutlet weak var firstImageView: UIImageView!
@IBOutlet weak var secondImageView: UIImageView!
@IBOutlet weak var thirdImageView: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
//cell reuse 시 잘못된 이미지 load 되는 것 방지
override func prepareForReuse() {
firstImageView.sd_cancelCurrentImageLoad()
secondImageView.sd_cancelCurrentImageLoad()
thirdImageView.sd_cancelCurrentImageLoad()
firstImageView.image = UIImage(named: "placeholder")
secondImageView.image = UIImage(named: "placeholder")
thirdImageView.image = UIImage(named: "placeholder")
}
}
728x90