給UITableView 添加長按手勢,識別長按哪一行。
長按手勢類UILongPressGestureRecognizer, 屬性minimumPressDuration表示最短長按的時間
添加手勢代碼:
UILongPressGestureRecognizer
* longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDo:)];
longPressGr.minimumPressDuration
= 1.0;
[self.tableView
addGestureRecognizer:longPressGr];
響應長按事件代碼:
-( void )longPressToDo:(UILongPressGestureRecognizer
*)gesture { if (gesture.state
== UIGestureRecognizerStateBegan) { CGPoint
point = [gesture locationInView:self.tableView]; NSIndexPath
* indexPath = [self.tableView indexPathForRowAtPoint:point]; if (indexPath
== nil)
return
; //add
your code here } }
|