//開啟編輯模式
- (void)openEditing
{
[self.tableView setEditing:YES animated:YES];
}
//批量刪除
- (void)deleteData
{
NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];
NSMutableArray *arrayM = [NSMutableArray array];
for (NSIndexPath *path in indexPaths) { //遍歷行號數組
Model *model = self.dataSource[path.row]; //通過行號下標找到對應行的模型數據
[arrayM addObject:model];
}
self.deleteArray = arrayM;
[self.dataSource removeObjectsInArray:self.deleteArray];
[self.tableView reloadData];
[self.deleteArray removeAllObjects];//刪除完成後,清空需要刪除的數組
[self.tableView setEditing:NO animated:YES];
}
PS:前提是在viewDidLoad中開啟批量編輯模式
self.tableView.allowsMultipleSelectionDuringEditing = YES;
PSS:自定義批量刪除樣式,需要在模型中設置狀態量,根據狀態量進行判斷是否將要刪除的那一行對應的模型加載到刪除數組中,再進行批量刪除