Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save imnaveensharma/ed0268715bb851c7c452c247f8c64626 to your computer and use it in GitHub Desktop.
Save imnaveensharma/ed0268715bb851c7c452c247f8c64626 to your computer and use it in GitHub Desktop.
Add Long Press Gesture Recognizer on Table Cell For Multiple Selection
private func setupLongPressGesture() {
let longPressGesture:UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(self.handleLongPress))
longPressGesture.minimumPressDuration = 1.0 // 1 second press
//longPressGesture.delegate = self
self.tblView.addGestureRecognizer(longPressGesture)
}
@objc func handleLongPress(_ gestureRecognizer: UILongPressGestureRecognizer) {
if gestureRecognizer.state == .began {
let touchPoint = gestureRecognizer.location(in: self.tblView)
if let indexPath = self.tblView.indexPathForRow(at: touchPoint) {
dLog(message: "Selected Cell Index :: \(indexPath.row)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment