【发布时间】:2018-04-28 15:38:13
【问题描述】:
我正在尝试做的是,当我点击单元格中的按钮时,该单元格中的按钮变得不可见。问题是当我点击按钮时,它变得不可见,但是当我滚动集合视图时,隐藏的按钮会从一个到另一个。例如,我点击它隐藏的第二个,但是当我滚动时,我看到第 7 个被隐藏了。每次我滚动隐藏按钮时都会发生变化。
这是我写的代码:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell : CollectionViewCellKharid3 = collectionView.dequeueReusableCell(withReuseIdentifier: "customcell3", for: indexPath) as! CollectionViewCellKharid3
cell.lblEsmeMahsul.text = mainCats[indexPath.row]
cell.imgMahsul.af_setImage(withURL: URL(string : (mainadress + "/Opitures/" + mainPicNumbers[indexPath.row]))!, placeholderImage: UIImage(named: "loadings" ))
cell.btnKharid.addTarget(self, action: #selector(btnColectionviewCellTapped), for : UIControlEvents.touchUpInside)
cell.btnKharid.tag = indexPath.row
cell.btnMosbat.addTarget(self, action: #selector(btnMosbatTapped), for : UIControlEvents.touchUpInside)
cell.btnMosbat.tag = indexPath.row
cell.configureCell()
return cell
}
@objc func btnColectionviewCellTapped(_ sender:UIButton){
// let indexPath : IndexPath = self.collectionview1.ind
print(sender.tag)
sender.isHidden = true
}
@objc func btnMosbatTapped(_ sender:UIButton){
let index = IndexPath(item: sender.tag , section: 0)
let cell = self.collectionviewForushVije.cellForItem(at: index) as? CollectionViewCellKharid3
cell?.lblTedad.text = "22"
print(sender.tag)
}
【问题讨论】:
-
覆盖 prepareforreuse 函数来设置所有的针刺材料。像按钮的可见性状态。单元格被重复使用,如果设置不正确,就会出现问题
标签: ios swift uicollectionview