美文网首页
cell 删除

cell 删除

作者: 全世界妳最美 | 来源:发表于2018-08-06 10:45 被阅读6次

1.在父类中,设置删除通用的方法

#pragma mark - 删除 tableView

//1.删除 cell可编辑

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{

    return NO;

}

//3.定义编辑样式

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return UITableViewCellEditingStyleDelete;


}

//4.

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return @"删除";

}

2.在具体子类中重写部分方法,和需要的方法

#pragma mark - 删除
//重写父类方法
//1.删除 cell可编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return NO;
//  return YES;
}

//3.删除数据 视图
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{
    if (editingStyle ==UITableViewCellEditingStyleDelete) {//如果编辑样式为删除样式
        
        if (indexPath.row<[self.arrData count]) {

            [self.arrData removeObjectAtIndex:indexPath.row];//移除数据源的数据
            //调取后台删除接口
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];//移除tableView中的数据
        }
    }
}

相关文章

网友评论

      本文标题:cell 删除

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