在.m文件中的viewDidLoad添加長按手勢
longPressGR = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressedOnCell:)];
longPressGR.minimumPressDuration = 0.5;
[self.tableView addGestureRecognizer:longPressGR];
在longPressedOnCell中實現獲取cell行號操作
-(void)longPressedOncell:(id)sender{
if ([(UILongPressGestureRecognizer *)sender state] == UIGestureRecognizerStateBegan) {
// aIndexPath = [self.tableView indexPathForCell:((UITableViewCell *)(longPressGR.view))];
CGPoint point = [(UILongPressGestureRecognizer *)sender locationInView:self.tableView];
aIndexPath = [self.tableView indexPathForRowAtPoint:point];
NSLog(@"indexPath = %d",aIndexPath.row);
index = aIndexPath.row;
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"刪除筆記" message:@"確定刪除?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];
[alert show];
[alert release];
}
}