【发布时间】:2013-02-21 19:36:12
【问题描述】:
所以我想删除表格视图中的行。
这是我的代码:
- (IBAction)done:(UIStoryboardSegue *)segue
{
DetailGodsViewController *detailController = [segue sourceViewController];
NSIndexPath *path = [NSIndexPath indexPathForRow:detailController.row inSection:detailController.section];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:path]
withRowAnimation:NO];
[self.listOfGoods deleteGood: detailController.row];
[[self tableView] reloadData];
[self dismissViewControllerAnimated:YES completion:NULL];
}
我在storyBoard中有ControlViewTable,当我点击ControlViewTable中的一行后,它会跳转到Detail view 还有其他信息,我也在这个函数中存储了关于行和部分的信息:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"ShowGoodDetails"]) {
DetailGodsViewController *detailViewController = [segue destinationViewController];
detailViewController.row = [self.tableView indexPathForSelectedRow].row;
detailViewController.section = [self.tableView indexPathForSelectedRow].section;
detailViewController.good = [self.listOfGoods getGoodAtIndex:detailViewController.row ];
}
还有一个detail view的按钮可以删除,点击后跳转到功能:
- (IBAction)done:(UIStoryboardSegue *)segue.
但它总是在 deleteRows 中崩溃。有人可以帮忙吗?
【问题讨论】:
-
您能否添加崩溃的原因和确切的行号,或者更好的是完整的堆栈跟踪?
-
当我尝试删除行时它崩溃 -> [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:path] withRowAnimation:NO];
-
由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无效更新:第0节中的行数无效。更新(2)后现有节中包含的行数必须相等更新前该节中包含的行数 (2),加上或减去从该节插入或删除的行数(0 插入,1 删除),加上或减去移入或移出该节的行数部分(0 移入,0 移出)。'