ios值UITableViewCell侧滑删除

来源:互联网 发布:c语言浮点数表示方法 编辑:程序博客网 时间:2024/06/07 06:04

侧滑删除效果

这里写图片描述

实现代码

#pragma mark  ------- UITableViewCell编辑模式-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{    return   UITableViewCellEditingStyleDelete;}//先要设Cell可编辑- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{    if (indexPath.section == 1) {        return YES;    }else{        return NO;    }}//进入编辑模式,按下出现的编辑按钮后- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{    WSMesageListModel *messageListModel = _dataSource[indexPath.row];    WSMessageDeleteRequest *messageDeleteRequest = [WSMessageDeleteRequest Request];    messageDeleteRequest.mid = messageListModel.ID;    [WSAction Send:messageDeleteRequest success:^(BOOL isSuccessed, id responseData) {        if (isSuccessed) {            [_dataSource removeObjectAtIndex:indexPath.row];            [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];        }    } failed:^(NSError *error) {    }];}//修改编辑按钮文字- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{    return @"删除";}//设置进入编辑状态时,Cell不会缩进- (BOOL)tableView: (UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath{    return NO;}

以上代码是实现侧滑删除的代理方法。

原创粉丝点击