ios8 / Swift:UICollectionView Cell里面的按钮?

时间:2015-02-05 15:32:06

标签: swift ios8 uicollectionview ibaction

我正在尝试构建预览"上传图片"使用集合视图到服务器,但我不知何故坚持删除 - 或者准确地说如何在单元格中正确连接Button?

Collection Cell

单击X(单元格内的按钮),用户应从上传数组中删除此UIImage,该数组是其父ViewController的一部分。

您是否应该在自定义单元格类或普通ViewController中处理IBAction单击?

这样做的正确方法是什么?你应该根据索引在按钮上使用标签,然后删除图像@index,还是应该将整个数组移交给单元格并在点击后返回?

1 个答案:

答案 0 :(得分:2)

假设按钮的Touch Up Inside事件连接了以下功能。

func deleteButtonPressed(button: UIButton) {
    let touchPoint = collectionView.convertPoint(CGPoint.zeroPoint, fromView: button)
    if let indexPath = collectionView.indexPathForItemAtPoint(touchPoint) {
        // now you know indexPath. You can get data or cell from here. 
    }
}