實現三個代理方法即可
-(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,好的,現在終於操作流暢了。