我尝试设法从中删除行,该行UITable
是的一部分UIViewController
。我使用Edit
导航栏中的按钮。击中它将使表行进入编辑模式。但是,当按行中的删除按钮...'Invalid update: invalid number of rows in section 0….
时,使用以下命令时出现错误:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:YES];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSMutableArray *work_array = [NSMutableArray arrayWithArray:self.inputValues];
[work_array removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
我在这里想念什么?在苹果公司的文件似乎是某种方式已经过时。谢谢
问题很简单。从表中删除行之前,您没有正确更新数据模型。
您要做的就是创建一些新数组,并从中删除一行。那是没有意义的。您需要更新其他数据源方法(例如)使用的相同数组numberOfRowsInSection:
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句