//首先我们需要把编辑模式设定为删除
-(UITableViewCellEditingStyle)tableView:(UITableView*)table editingStyleForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
//然后设置删除按钮的文字标题
-(NSString*)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"删除";
}
//点击删除按钮后进行数据处理
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
/*
可以在此进行数据处理
*/
NSMutableArray*muarr=[NSMutableArray arrayWithArray:self.dataArray[indexPath.section]];
[muarr removeObjectAtIndex:indexPath.row];
[self.dataArray replaceObjectAtIndex:indexPath.section withObject:muarr];
[self.mainTableView reloadData];
}
}
联系客服