
编辑的步骤
1、self让tableView处于编辑状态
3、指定tableView编辑样式(添加、删除)
4、编辑完成(先操作数据源,在修改UI)
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
// 1、应当先删除对应行的数据
// 2、再将对应行的单元格从表视图中删除
[self.datasource removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationMiddle];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the apPRopriate class, insert it into the array, and add a new row to the table view
// 1、现在数组中插入对应的对象
// 2、创建对应对象的indexPath
// 3、根据indexPath在表视图中的位置插入对应行
[self.datasource addObject:@"新插入的数据"];
NSIndexPath *insertPath = [NSIndexPath indexPathForRow:self.datasource.count - 1 inSection:0];
[tableView insertRowsAtIndexPaths:@[insertPath] withRowAnimation:UITableViewRowAnimationMiddle];
}
}
当表格被拖拽后会相应此方法,

当表格处于编辑状态时,可以通过以下方法设置相应的表格是否与许被编辑
