说明:虽然是tableview中cell的长按手势  但是手势是添加在tableview上的  

UILongPressGestureRecognizer *longpress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(pressAction:)];
    [self.tableView addGestureRecognizer:longpress];

- (void)pressAction:(UILongPressGestureRecognizer *)longPressGesture
{
    if (longPressGesture.state == UIGestureRecognizerStateBegan) {//手势开始
        CGPoint point = [longPressGesture locationInView:self.tableView];
        NSIndexPath *currentIndexPath = [self.tableView indexPathForRowAtPoint:point]; // 可以获取我们在哪个cell上长按
        NSLog(@"%ld",currentIndexPath.section);
    }
    if (longPressGesture.state == UIGestureRecognizerStateEnded)//手势结束
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"是否删除" message:nil delegate:self cancelButtonTitle:@"确认" otherButtonTitles:@"取消", nil];
        
        [alert show];
        
    }
}

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄