长按手势获取UITableView的indexPath值,删除某行

来源:互联网 发布:打字员软件 编辑:程序博客网 时间:2024/06/05 13:24

- (void)viewDidLoad

{

//给cell加长按手势

UILongPressGestureRecognizer *gestureLongPress = [[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(gestureLongPress:)];

gestureLongPress.minimumPressDuration =1;

[self.tableV0addGestureRecognizer:gestureLongPress];

[gestureLongPressrelease];

}




#pragma mark - 长按手势


- (void)gestureLongPress:(UILongPressGestureRecognizer *)gestureRecognizer

{

   CGPoint tmpPointTouch = [gestureRecognizerlocationInView:self.tableV0];

   if (gestureRecognizer.state ==UIGestureRecognizerStateBegan) {

       NSIndexPath *indexPath = [self.tableV0indexPathForRowAtPoint:tmpPointTouch];

       if (indexPath ==nil) {

            NSLog(@"not tableView");

        }else{

           focusSection = [indexPathsection];

           focusRow = [indexPathrow];

            

           NSLog(@"%d",focusSection);

           NSLog(@"%d",focusRow);

            

            

           deletebtn.hidden =NO;

        }

    }

}



//删除

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:focusRow inSection:focusSection];

[self.tableV0 deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];