在.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];
}
}