//默认的所有的编辑的状态(2种(删除、编辑))是删除
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
returnUITableViewCellEditingStyleInsert;
}
- (IBAction)editButtonPress:(UIButton *)sender
{
//初始为NO,记录状态
[self.tableViewsetEditing:!self.tableView.editinganimated:YES];
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//根据(处理)样式类型处理事件
if (editingStyle==UITableViewCellEditingStyleDelete)
{
[self.mutableArrayremoveObjectAtIndex:indexPath.row];//删除数组中的数据
[tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:YES];//删除单元格
}
if (editingStyle==UITableViewCellEditingStyleInsert)
{
Student *stu=[[Studentalloc]init];
[self.mutableArrayinsertObject:stu atIndex:indexPath.row];
[tableView insertRowsAtIndexPaths:@[indexPath]withRowAnimation:YES];
[sturelease];
}
}
(未完待续)