我在删除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;
}
}
答案 0 :(得分:-1)
完全删除以下内容:
sect = [listArray objectAtIndex:indexPath.row];
[sect removeObjectAtIndex:indexPath.row];
和
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
只需致电[listArray removeObjectAtIndex:indexPath.row];
,然后致电reloadData
以刷新UITableView
。