-1

I have a custom UITableView cell and I want to add a long press gesture recognizer to it. Currently, I'm doing it as so:

    longPressGesture.minimumPressDuration = 1.0
    longPressGesture.addTarget(self, action: "testFeedback")
    cell.addGestureRecognizer(longPressGesture)

I'm doing it programmatically because I could not find a good way to detect which cell was tapped within an IBAction. However, I'm having a hard time getting this to work I want to pass a parameter through the selector. I am not opposed to doing this in storyboards, but would appreciate some guidance on it.

Thanks!

1 Answers1

1

testFeedback function should look like this

func testFeedback(gestureRecognizer:UIGestureRecognizer) {

    if (gestureRecognizer.state == UIGestureRecognizerState.Ended) {
        var point = gestureRecognizer.locationInView(self.tableView)
        if let indexPath = self.tableView.indexPathForRowAtPoint(point)
        {
            println(indexPath.row) /// long press ended
        }
    }
    else if (gestureRecognizer.state == UIGestureRecognizerState.Began){
           /// long press started
    }
}
Özgür Ersil
  • 6,909
  • 3
  • 19
  • 29