未在CollectionView的垂直索引处设置本地图像

时间:2019-08-09 12:35:45

标签: ios uikit

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

0 个答案:

没有答案