Reputation: 1623
I am trying to build a preview of "Upload Images" to a Server using a collection view but I am somehow stuck on the deletion - or to be precise on how to correctly wire up the Button inside the Cell?
On click of X(a button inside the cell) the user should delete this UIImage from the upload array which is part of his parent ViewController.
Are you supposed to handle the IBAction click inside the custom cell class or in the normal ViewController?
What is the correct way to do it? Should you use tags on the buttons depending on index and then remove the image @index or should you handover the full array to the cell and return it after click?
Upvotes: 2
Views: 2685
Reputation: 15464
Suppose button's Touch Up Inside event is connected the function below.
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.
}
}
Upvotes: 2