gpt4 book ai didi

iphone - 删除表格 View 单元格但显示 "invalid number of rows"

转载 作者:行者123 更新时间:2023-11-29 11:02:57 24 4
gpt4 key购买 nike

我的 TableView 数据源来自一个数组,它从托管对象上下文的 executeFetchRequest 方法中获取数据。在 commitEditingStyle 委托(delegate)中,我收到了这个错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1),

代表:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.managedOjbectContext deleteObject:[self.myEvents objectAtIndex:indexPath.row]];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView reloadData];
}
}

最佳答案

错误说明了一切,您删除了一行,但您的代表仍然说它在那里。

我的猜测是您没有从 self.myEvents 中删除您的对象。从托管上下文中删除对象不会将其从数组中删除。

假设 self.myEvents 是一个 NSMutableArray*

[self.myEvents removeObjectAtIndex:indexPath.row]

关于iphone - 删除表格 View 单元格但显示 "invalid number of rows",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15006494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com