场景:
选择图片上传到服务器,服务器返回图片地址,根据地址展示图片,在上传一定数量图片时,偶现图片错乱问题,如图
复现问题
正常展示
解决方案:
1.防止cell复用【会影响性能,不建议使用,适合应急】
在使用cell前根据indexpath section row注册cell
let identifier = String.init(format:"%ld%ld",indexPath.section,indexPath.row)
collectionView.register(UINib.init(nibName: "PhotoShowCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: identifier)
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) as! PhotoShowCollectionViewCell
2.为UIcollectionViewCell添加代理,在代理方法中刷新新上传的cell,不影响之前cell复用
extension ReportPhotoViewController: PhotoShowCollectionViewDelgate {
func getImageData(cell: UICollectionViewCell, imageData: Data) {
cell.reloadInputViews()
}
}