tableView左滑删除功能

实现三个代理方法即可

-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
    return @"删除";
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{   if (!indexPath.section) return UITableViewCellEditingStyleNone; // 第一组家和公司不提供左滑删除功能
    return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        
        [self.commonPlaceArray removeObjectAtIndex:indexPath.row];
        [self.tableView deleteRowsAtIndexPaths:@[indexPath]
                              withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView reloadData];
    }
}

上面说漏了一点,就是有个代理方法是开启允许进入编辑状态的,这样才可以进行左滑或者添加的其他操作,注意当你左滑后,没有把这个cell滑回去,这时候如果你在返回上一个页面可能会崩溃,这个时候你需要在viewWillDisappear方法中将这个编辑状态置为NO,好的,现在终于操作流畅了。

原文地址:https://www.cnblogs.com/songxing10000/p/4576791.html