获取长按手势所点击的cell的行号

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




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章