A
A
Aleksandr Govorukhin2017-06-25 13:09:26
iOS
Aleksandr Govorukhin, 2017-06-25 13:09:26

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

1 answer(s)
A
Aleksandr Govorukhin, 2017-06-25
@SnapSh0t

696efc836bd045978039a2a0ee992ff5.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question