Answer the question
In order to leave comments, you need to log in
How to remove image from UICollectionView in Swift 3?
Hello! How to remove image on button click? I have an array of images stored in CoreData and when I receive it, I unzip the package and display it in the collection view, I can’t figure out how to implement deletion on click?
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Collection_cell", for: indexPath) as! CollectionViewCell
let images = NSKeyedUnarchiver.unarchiveObject(with: recipe.imageRecipe! as Data) as! NSMutableArray
let img = UIImage(data: images[indexPath.row] as! Data)!
cell.recipeImageView.image = img
cell.deleteImage.tag = indexPath.row
cell.deleteImage.addTarget(self, action: #selector(EditRecipeTableViewController.deleteImg(_:)), for: .touchUpInside)
return cell
}
@IBAction func deleteImg(_ sender: UIButton){
print("Button pressed ")
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question