美文网首页
tableview做长按删除

tableview做长按删除

作者: 梁苏珍 | 来源:发表于2018-08-31 16:39 被阅读0次

     UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(lpGR:)];

            //设定最小的长按时间 按不够这个时间不响应手势

            longPressGR.minimumPressDuration=0.7;

            [celladdGestureRecognizer:longPressGR];

    #pragma mark -实现手势对应的功能

    -(void)lpGR:(UILongPressGestureRecognizer *)lpGR

    {

        if (lpGR.state == UIGestureRecognizerStateBegan) {//手势开始

            CGPointpoint = [lpGRlocationInView:self.tableViewNoticeDetails];

            NSIndexPath*indexPath =  [self.tableViewNoticeDetailsindexPathForRowAtPoint:point];

            if(indexPath !=nil){

                NSIntegerindexNum = indexPath.row;

                NSLog(@"点击的是第%ld行",(long)indexNum);

            }

        }

        if (lpGR.state == UIGestureRecognizerStateEnded){

            //手势结束

            [self longPressDelete];//添加弹窗

        }

    }

    -(void)longPressDelete

    {

        ACActionSheet *actionSheet = [[ACActionSheet alloc] initWithTitle:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@[@"删除"] actionSheetBlock:^(NSInteger buttonIndex) {

            if(buttonIndex ==0) {

            }

        }];

        [actionSheetshow];

    }

    相关文章

      网友评论

          本文标题:tableview做长按删除

          本文链接:https://www.haomeiwen.com/subject/kdqewftx.html