删除表格视图中的单元格

时间:2011-09-08 02:12:39

标签: iphone tableview

我在删除tableview中的单元格时遇到问题,当我按下删除按钮时,我的程序会崩溃。

这是我的代码:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the managed object at the given index path
        sect = [listArray objectAtIndex:indexPath.row];
        [sect removeObjectAtIndex:indexPath.row];

        // Update Event objects array and table view
        [listArray removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
        tableView.editing = YES;

        }
}

1 个答案:

答案 0 :(得分:-1)

完全删除以下内容:

sect = [listArray objectAtIndex:indexPath.row];
[sect removeObjectAtIndex:indexPath.row];

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];

只需致电[listArray removeObjectAtIndex:indexPath.row];,然后致电reloadData以刷新UITableView