IOS adds a long-pressed gesture to the cell of tableview twice (UILongPressGestureRecognizer)
Here we add a long-pressed gesture for tableview
UILongPressGestureRecognizer * longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget: self action: @ selector (longPressAction :)];
LongPressGr. minimumPressDuration = 0.5f;
LongPressGr. numberOfTouchesRequired = 1;
[_ TableView addGestureRecognizer: longPressGr];
[LongPressGr release];
At this time, we will find that longPressAction: This method will be executed twice each time we hold down tableView and release it.
-(Void) longPressAction :( UILongPressGestureRecognizer *) longPress
{
If (longPress. state = UIGestureRecognizerStateBegan ){
CGPoint point = [longPress locationInView: _ tableView];
NSIndexPath * indexPath = [_ tableView indexPathForRowAtPoint: point]; // you can obtain the cell on which we press
If (indexPath! = Nil ){
NSLog (@ "% ld", indexPath. row );
}
}
}