我有一些带有一些细胞的 UICollectionView
.
我有一个奇怪的错误,点击一个单元格有时会记录错误的单元格 .
行为:
如果我有单元格A和单元格B,然后单击单元格A然后单击单元格B,单击单元格B将单击单元格A进行注册 .
根据这一点,一旦视图加载被忽略,首先单击任何单元格 . 如果我在点击单元格B之前两次单击单元格A,则最终单击单元格B一次,单击单元格一次 .
我很困惑 . 有什么帮助吗?
我的 didSelectItemAt
功能:
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
{
// Display selected Item
let prodForPurchase = products[indexPath.row]
let prodForPurchaseID = prodForPurchase.getUniqueID()
let prodForPurchasePrice = prodForPurchase.getPrice()
prodForPurchase.toggleProductSelected()
if (prodForPurchase.isProductMarked())
{
// Product not yet marked for purchase. Need to add it for purchase
m_productsToPurchaseList[prodForPurchaseID] = prodForPurchasePrice
m_totalToPay += prodForPurchasePrice
}
else
{
// Product already marked for purchase. Need to remove it from purchase
m_productsToPurchaseList.removeValue(forKey: prodForPurchaseID)
m_totalToPay -= prodForPurchasePrice
}
ProductsCollection.reloadData()
self.m_totalSumLabel.text = String(self.m_totalToPay)
}