【发布时间】:2017-02-17 07:28:34
【问题描述】:
我有一个UICollectionView,它使用自定义xib 文件作为它的单元格。在单元格中,我有一个 ImageView 复选框。我想在录制时更改`ImageView1 的图像。我尝试了以下代码 sn-p 但它不适合我
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
}
在这段代码中,我尝试在didSelectItemAt 中更改ImageView 的图像。
我的自定义xib文件如下。
请提出一种使它起作用的方法。谢谢。
【问题讨论】:
-
请问您是否尝试过我的解决方案?
-
@KrishnaCA 我通过稍微调整您的建议解决了问题。感谢您的领导。
-
这与我的解决方案几乎相似。但是,您没有使用完整的布尔数组,而是使用 int 数组来减少内存占用。不错
标签: ios swift swift3 uicollectionview uicollectionviewcell