我有一個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