我有一个UICollectionView,并且在我的customCell 3按钮中存在
第一次重新加载数据时,一切都很好,但是在重新加载数据时,其中一个按钮返回nil
怎么了?
我该怎么办?
func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let reuseIdentifier = "ProductCollectionViewCell"
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier,for: indexPath) as! ProductCollectionViewCell
let product = realm.objects(ProductModelDB.self)
for i in 0..<product.count {
if product[i].id == self.productsArray[indexPath.row].id {
productsArray[indexPath.row].count = product[i].count
}
}
let object = productsArray[indexPath.row]
let url:URL! = URL(string: (object.mainImageUrl))
cell.productImage.kf.setImage(with: url)
cell.nameLabel.text = object.name
cell.brandLabel.text = object.brandName
if object.isSelected {
cell.addingView.alpha = 1
}else{
cell.addingView.alpha = 0
}
cell.numberLabel.text = "\(object.count)"
cell.plusBtn.addTarget(self, action: #selector(plus(_:)), for: .touchUpInside)
cell.plusBtn.tag = indexPath.row
cell.minusBtn.addTarget(self, action: #selector(minus(_:)), for: .touchUpInside)
cell.minusBtn.tag = indexPath.row
cell.addingButton.addTarget(self, action: #selector(adding(_:)), for: .touchUpInside)
cell.addingButton.tag = indexPath.row
cell.ui()
return cell
}