在collectionView
的第一个reloadData
中,单元格中的数据设置正确,但是如果我们在执行任何任务后重新加载collectionView
,则本地图像会在那里更改。我不知道为什么,但是图像更改位置(indexPath)。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath)
-> UICollectionViewCell {
let cell = songListCollectionView.dequeueReusableCell(withReuseIdentifier: "SongCollectionViewCell", for: indexPath) as? SongCollectionViewCell
let getArtistOfWeekObject = self.getArtistOfWeekObjectList?.game?.locks![indexPath.row]
print(getArtistOfWeekObject as Any)
if getArtistOfWeekObject?.status == 1 {
cell?.lockImg.image = #imageLiteral(resourceName: "select")
cell?.numberLbl.text = "song \(indexPath.row + 1)"
} else if getArtistOfWeekObject?.playable == 1 {
cell?.lockImg.isHidden = true
cell?.numberLbl.text = "song \(indexPath.row + 1)"
} else {
cell?.lockImg.image = #imageLiteral(resourceName: "white_lock")
cell?.numberLbl.text = "song \(indexPath.row + 1)"
}
return cell!
}
在这里lockImg在重新加载后更改其indexPath