我有一个UICollectionView
,它使用定制的xib
文件作为它的单元格。在单元格中,我有一个ImageView
复选框。我想在录制时更改ImageView1的图像。我试着下面的代码片段,但是,它不适合我在UICollectionViewCell上点击更改ImageView图像
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! V_Cell
if show_delete == true {
cell.img_delete.image = UIImage(named: "checked")
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! V_Cell
// Configure the cell
let data = valves_[indexPath.row]
cell.v_name.text = data
if show_delete == true {
cell.img_delete.isHidden = false
} else if show_delete == false {
cell.img_delete.isHidden = true
}
return cell
}
工作在这个代码中,我试图改变的ImageView
图像中didSelectItemAt
。
我的自定义xib
文件如下。
请提出一个方法,使其工作。谢谢。
我可以知道您是否尝试过我的解决方案? – KrishnaCA
@KrishnaCA我通过对您的建议进行微调来解决问题。感谢领先。 –
这几乎看起来与我的解决方案类似。但是,您不是使用完整的布尔数组,而是使用int数组来减少内存足迹。尼斯 – KrishnaCA