代码改变世界

TableView的删除操作

2015-07-21 20:20  一树一菩提  阅读(419)  评论(0编辑  收藏  举报

 

 

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

    

    if (editingStyle != UITableViewCellEditingStyleDelete) return;//非编辑删除模式

    //先修改模型中的数据

    [persons removeObjectAtIndex:indexPath.row];

 

    //刷新表格

//下面的方法必须是模型里的行数和tableView中的行数必须一致

//    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];

    

    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];

    

}

 

 

 

- (IBAction)remove:(UIBarButtonItem *)sender {

    

    //进入编辑模式

    BOOL result = !self.tableView.isEditing;

    [self.tableView setEditing:result animated:YES];

 

}