I had similar issue with iOS18.(issue exists in below code)
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FTShelfTagsPageCell", for: indexPath) as? FTShelfTagsPageCell else {
return UICollectionViewCell()
}
cell.selectionBadge?.isHidden = viewState == .none ? true : false
if indexPath.section == 0 {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FTShelfTagsBooksCell", for: indexPath) as? FTShelfTagsBooksCell else {
return UICollectionViewCell()
}
return cell
} else if indexPath.section == 1 {
let item = pages[indexPath.row]
cell.updateTagsItemCellContent(tagsItem: item, isRegular: self.traitCollection.isRegular)
}
cell.isSelected = true
return cell
}
It is dequeuing 2 cells though I return single cell.
After simplification like below, issue got fixed.
(only 1 cell ll be dequeued at a time.)
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.section == 0 {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FTShelfTagsBooksCell", for: indexPath) as? FTShelfTagsBooksCell else {
return UICollectionViewCell()
}
return cell
} else {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FTShelfTagsPageCell", for: indexPath) as? FTShelfTagsPageCell else {
return UICollectionViewCell()
}
let item = pages[indexPath.row]
cell.selectionBadge?.isHidden = viewState == .none ? true : false
cell.updateTagsItemCellContent(tagsItem: item, isRegular: self.traitCollection.isRegular)
cell.isSelected = true
return cell
}
}