我有一個UICollectionView在我的項目中,我添加了在每個單元格中添加的項目的數量,並在UIBarButtonItem中顯示總數。但是,當我瀏覽視圖時,數字會不斷變化。我知道這個問題與收集和表格視圖重複使用單元有關,並且我已經做了大量的研究,但是我無法解決這個問題。重寫「prepareForUse()」也沒有幫助。如果我天真的話,我還是個初學者,所以請原諒我。提前致謝。通過UICollectionView滾動不斷更新值
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = trayCell.dequeueReusableCell(withReuseIdentifier: "trayCell", for: indexPath) as! TrayItemCollectionViewCell
//initializing labels
if let quantity = arrayOfOrders[indexPath.row]["quantity"] as? Int{
totalQuantity += quantity
trayButton.title = "\(totalQuantity)"
}
return cell
}
您試圖顯示一個欄按鈕標題在整個集合視圖中的項目總數? – jegadeesh
@Bader Yusuf Serhan改變或重複有不同之處嗎? –
請顯示收集視圖的更多代碼 – 3stud1ant3