What is the most common way to delete cells from a UICollectionView - Swift

Viewed 1653

What is the most common way to delete cells from a UICollectionView?

In a UITableView I use the editActionsForRowAt or editingStyle methods to delete rows, does UIControllerView has something similar or you need to implement your own deleting method?

What I have is a UICollectionView with a lot of photos where each cell/photo is attached to a segue which takes you to a larger version of the photo.

The easiest way I could be to do it in the didSelectItemAt method but in my case that is not an option since as soon as a photo is tapped it segues to the other viewController (larger image).

What would be the best way to add a deleting functionality in a situation like the one I'm describing above?

The following threads show how to delete using the didSelectItemAt.

How to add a delete button to Collection View Cell in Swift?
How to delete item from collection view?

CODE

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return fruits.count
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "fruitCustomCell", for: indexPath) as! fruitCollectionViewCell

    cell.labelFruitName.text = fruits[indexPath.row].fruitName
    return cell
}

App Diagram

enter image description here

0 Answers
Related