我有一个 UITableViewController 管理分组的 tableView。 tableView 是从 fetchedResultsController 填充的。
如果我点击Edit导航栏中的按钮,然后选择一行并单击Delete按钮,该行被删除,一切顺利结束。
但是,如果我滑动以显示连续的“删除”按钮并单击“删除”按钮,应用程序将崩溃并出现以下错误:
2010-01-06 15:25:18.720 Take10[14415:20b] 严重的应用程序错误。核心数据更改处理期间捕获异常:-[NSCFArray objectAtIndex:]: index (1)超出边界(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();
}
}
}
有任何想法吗???
Thanks
Jk
Jeff LaMarche 在 NSFetchedResultsController 方面做了一些出色的工作。
尝试在这里使用他的模板:http://iphonedevelopment.blogspot.com/2010/01/navigation-based-core-data-application.html http://iphonedevelopment.blogspot.com/2010/01/navigation-based-core-data-application.html
看看这是否能解决您的问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)