首页 > 解决方案 > 滚动 Swift 4 时,Collectionview 上的图像混合在一起

问题描述

我在单元格视图上有一个带有图像的集合视图。但是当我向下滚动收藏视图时,我的一些图像是混合的。我没有使用任何库将图像插入 UIImageView。

这是我重用集合视图单元的代码。

cell.lvTitle.text = dataImage[indexPath.row]["nama"]
cell.delegate = self as! buttonClickedDelegate
cell.imageCode = dataImage[indexPath.row]["imageCode"]
cell.seq = dataImage[indexPath.row]["seq"]
cell.etcName = ""

if dataImage[indexPath.row]["tipe"] == "1" {
    let data = NSData(contentsOf: NSURL(string: dataImage[indexPath.row]["image"]!)! as URL)
    cell.imgFoto.image = UIImage(data: data! as Data)      
}

if dataImage[indexPath.row]["tipe"] == "0"{
    let data = Data(base64Encoded: dataImage[indexPath.row]["image"]!)
    cell.imgFoto.image = UIImage(data: data!)
}

标签: iosswiftuicollectionviewuiimageuicollectionviewcell

解决方案


正如qtngo在评论中提到的那样。

我忘了覆盖视图单元格上的 prepareForReUse 。多谢


推荐阅读