I have go this uicollectionviewcell
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
This happens because cells are being reused. The easiest way to handle this is to store index paths of cells with text in your view controller. When cell is dequeued just check if index path is present in stored array and layout accordingly.
In your ViewController
var cellsWithText: [IndexPath] = []
In cellForItemAt indexPath
...
cell.postImage.image = nil
cell.cellConstraintsWithoutImageWithText()
if !cellsWithText.contains(indexPath) {
cellsWithText.append(indexPath)
}
...
Now at the beginning at cellForItemAt indexPath
if let CurrentPost = posts[indexPath.row] as? Post {
if cellsWithText.contains(indexPath) {
// layout for text
} else {
// layout for image
}
I also noticed that your'e using posts[indexPath.row]
but your using the collectionView, that doesn't have rows and has item
instead. That also might be the issue.