1

In my CollectionView I am trying to hide content of cells which indexPath is more than 0, by calling blockContent func on cell. But somehow, after going back and forth threw cells, this func got called even on the first cell. How can i Fix it? Thanks

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as? InsightCollectionViewCell else { return UICollectionViewCell()}
    
    if indexPath.item > 0 {
        cell.blockContentWithSpoiler()
        cell.delegate = self
    }
    
    return cell
}

Tried to use cell.prepareForReuse() but that didnt help...

Togosling
  • 21
  • 1
  • Do you have a corresponding `unblockContentWithSpoiler()` function? – DonMag Jun 06 '23 at 15:05
  • 1
    Table view cells that are scrolled off screen are cached and re-used for other rows. You are very probably seeing a cell that was used for an index path row > 0 being reused for index path row 0 when scrolling back. You need to explicitly show the content for row 0 to undo the effect of the same cell instance previously being used for a block row. – Geoff Hackworth Jun 06 '23 at 15:24

0 Answers0