0
我必須走這uicollectionviewcellUICollectionViewcell調用函數遍地
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
}
我的目標是確定基於缺乏或圖像和text.Now的存在其功能是目標的問題是所有這些功能被調用,因爲一些細胞確實有圖像cellConstraintsWithImageWithText
正在被調用,其他人沒有它們,所以cellConstraintsWithoutImageWithText
正在被調用。我怎樣才能爲單個細胞而不是所有細胞調用單個函數?
這不正是我在做什麼? – sakoaskoaso
@sakoaskoasko你正在存儲帖子,我提供存儲索引路徑。在初始出列時,只需將單元格的索引路徑添加到數組中(如果它具有文本)。當集合視圖將再次取消該單元格時,它應檢查此單元格的索引路徑是否存在於數組中。如果是這樣,這是一個文字佈局,如果不是圖像。 – inokey
@sakoaskoaso嘿,我用一些代碼更新了答案,並且還注意到我對indexPath.row的評論 – inokey