1

The goal is to handle swipes on UICollectionView cells. Each swipe left should present a delete option for the cell upon which the swipe occurred.

The current implementation attaches a swipe gesture recognizer to the UICollectionView then checks for the cell as follows:

let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(cellSwiped))
swipeGesture.direction = .Left
collectionView.addGestureRecognizer(swipeGesture)

func cellSwiped(gestureRecognizer : UISwipeGestureRecognizer) {
    let point = gestureRecognizer.locationInView(collectionView)
    if let indexPath = collectionView.indexPathForItemAtPoint(point) {
        // Do stuff
    }
}

The alternative is to customize the UICollectionViewCell to handle swipes.

What are the pros/cons of each? Are both equally good?

Crashalot
  • 33,605
  • 61
  • 269
  • 439

1 Answers1

0

You should add gesture in each cell, it'll make you can control easilly, and it'll make your code clean

Giang
  • 2,384
  • 2
  • 25
  • 26