獲取長按手勢所點擊的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];
    }
}




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