@sakoaskoaso Эй, я обновил ответ с помощью некоторого кода, а также заметил мое замечание о indexPath.row
я есть этот uicollectionviewcell
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! PostCell
if let CurrentPost = posts[indexPath.row] as? Post{
//determine which constraint to call
if(CurrentPost.PostText != nil){
if(CurrentPost.PostImage != nil){
cell.postImage.image = CurrentPost.PostImage
cell.cellConstraintsWithImageWithText()
}else{
cell.postImage.image = nil
cell.cellConstraintsWithoutImageWithText()
}
}else{
cell.postImage.image = CurrentPost.PostImage
cell.cellConstraintsWithImageWithoutText()
}
}
return cell
}
Моя цель состоит в том, чтобы определить, какую функцию нужно достичь, основываясь на отсутствии или наличии изображения и текста. Теперь проблема в том, что все эти функции вызываются, потому что в некоторых ячейках есть изображенияcellConstraintsWithImageWithText
называется, другие не имеют их такcellConstraintsWithoutImageWithText
Как я могу вызвать одну функцию для одной ячейки, а не для всех ячеек?