【发布时间】:2021-04-27 07:33:58
【问题描述】:
我在其中有一个集合视图和图像视图,我添加了一个UIButton 以在选择后删除图像。当我单击按钮时它崩溃并给我这个错误:
AdPostViewController deleteUser]:无法识别的选择器发送到实例 0x7fb588d5b7f0
为什么会发生这种情况,我该如何解决?这是我的代码:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImageCell", for: indexPath) as! ImageCell
let img = self.PhotoArray[indexPath.row]
cell.image.image = img
cell.deleteButton?.layer.setValue(indexPath.row, forKey: "index")
cell.deleteButton?.addTarget(self, action: Selector(("deleteUser")), for: UIControl.Event.touchUpInside)
return cell
}
func deleteUser(_ sender: UIButton) {
let i: Int = (sender.layer.value(forKey: "index")) as! Int
PhotoArray.remove(at: i)
// PhotoArray.removeAtIndex(i)
ImagesCollectionView.reloadData()
}
【问题讨论】:
标签: ios swift uicollectionview uiimageview selector