Khoury Khoury - 1 year ago 85
Swift Question

How to make a swipeable collection view cell to show delete button Swift

How can I make a swipeable collection view cell to show a delete button in swift?

I have a function to delete a cell with this code

func reset(sender: UISwipeGestureRecognizer) {

let cell = sender.view as! UICollectionViewCell
let i = self.collectionView.indexPathForCell(cell)!.item
self.collectionView.reloadData() // replace favoritesCV with your own collection view.

Which is called with this gesture

let cSelector = #selector(DateMenuViewController.reset(_:))
let UpSwipe = UISwipeGestureRecognizer(target: self, action: cSelector )
UpSwipe.direction = UISwipeGestureRecognizerDirection.Left

But I would like to have a gesture pretty much exactly the same as in the mail app, that is slide to the left on a cell and it will show a delete button?


Answer Source

I don't think UICollectionView provides that convenience (you probably saw it in UITableView). It means you'll probably have to implement it by yourself.