我有一个 UITableViewController 管理一个分组的 tableView。tableView 由 fetchedResultsController 填充。
如果我单击 NavigationBar 中的Edit按钮,然后选择一行并单击Delete按钮,则该行被删除并且一切顺利。
但是,如果我连续滑动以显示“删除”按钮并单击“删除”按钮,应用程序将崩溃并出现以下错误:
2010-01-06 15:25:18.720 Take10 [14415:20b] 严重的应用程序错误。在核心数据更改处理期间捕获到异常:-[NSCFArray objectAtIndex:]: index (1) beyond bounds (1) with userInfo (null)
2010-01-06 15:25:18.721 Take10 [14415:20b] 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“***-[NSCFArray objectAtIndex:]:索引 (1) 超出范围 (1)”
当然,错误中的索引号会根据我尝试删除行的部分中的行数而变化,并且该数字比尝试删除后表部分中剩余的行数多 1。
这是我尝试从 fetchedResultsController 中删除数据的代码。相同的方法对这两种情况都有反应,所以我不明白为什么在刷卡时它会崩溃。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the managed object for the given index path
NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
[context deleteObject:[fetchedResultsController objectAtIndexPath:indexPath]];
// Save the context.
NSError *error = nil;
if (![context save:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
}
有任何想法吗???
谢谢
杰克