ios 實現在tableViewCell上面添加長按手勢 刪除該條cell以及列表後台資料等

來源:互聯網
上載者:User

標籤:other   結束   提示   方法   poi   text   rem   ios   led   

自己的代碼  需要   把屬性更改成自己要使用的

//建立長按手勢

    在cellForRowAtIndexPath代理方法中

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

                //設定最小的長按時間 按不夠這個時間不響應手勢

                longPressGR.minimumPressDuration = 1;

                [cell addGestureRecognizer:longPressGR];

//實現手勢對應的功能

-(void)lpGR:(UILongPressGestureRecognizer *)lpGR

{

    if (lpGR.state == UIGestureRecognizerStateBegan) {//手勢開始

        CGPoint point = [lpGR locationInView:self.tbFirst];

        self.index = [self.tbFirst indexPathForRowAtPoint:point]; // 可以擷取我們在哪個cell上長按

        self.indexNum = self.index.row;

    }

    if (lpGR.state == UIGestureRecognizerStateEnded)//手勢結束

    {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"是否刪除" message:nil delegate:self cancelButtonTitle:@"確認" otherButtonTitles:@"取消", nil];

        [alert show];

    }

}

 //提示框代理方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex == 0) {

        NSDictionary * dic = self.hopeDs[self.indexNum];

        NSString *url = [NSString stringWithFormat:@"%@%@",JJBaseUrl,@"/v1/infomarket/delPost"];

        NSMutableDictionary *params = [NSMutableDictionary dictionary];

        params[@"postId"] = dic[@"id"];

        params[@"ticket"] = [JJUserInfoModel userInfoFromFile].ticket;

        [JJHttpTools deleteUrl:url params:params success:^(id json) {

            [JJMBProgressTool showSuccessProgressViewWithText:@"已刪除"];

            [self.hopeDs removeObjectAtIndex:self.indexNum];

            //刪除列表內容

            [self.tbFirst deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.index] withRowAnimation:UITableViewRowAnimationFade];

        } failure:^(NSError *error) {

            

        }];

    }else{

        

    }

}

 

ios 實現在tableViewCell上面添加長按手勢 刪除該條cell以及列表後台資料等

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.