1.添加编辑按钮
self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.navigationItem.rightBarButtonItem.title = @"编辑";
2.
//tableView处于可编辑状态
- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:animated];
[self.navigationItem setHidesBackButton:editing animated:animated];
if (editing) {
self.navigationItem.rightBarButtonItem.title = @"完成";
} else{
self.navigationItem.rightBarButtonItem.title = @"编辑";
}
}
3.//cell处于可编辑状态
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
4.//tableView样式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleDelete;
}
5.//提交编辑状态
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
NSMutableArray *group = self.allPeopleArray[indexPath.section];
[group removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
注释:第二步是自己查资料加上自己胡乱想出来的,也是成功实现了功能,但其原理不太懂得
附图:
点击编辑
删除之后点击完成