グループ化されたtableViewを管理するUITableViewControllerがあります。tableViewは、fetchedResultsControllerから入力されます。
ナビゲーションバーの[編集]ボタンをクリックしてから行を選択し、[削除]ボタンをクリックすると、行が削除され、すべてが正常に終了します。
ただし、スワイプして[削除]ボタンを続けて表示し、[削除]ボタンをクリックすると、アプリがクラッシュして次のエラーが発生します。
2010-01-06 15:25:18.720 Take10 [14415:20b]重大なアプリケーションエラー。Core Data変更処理中に例外がキャッチされました:-[NSCFArray objectAtIndex:]:インデックス(1)が範囲を超えています(1)with userInfo(null)
2010-01-06 15:25:18.721 Take10 [14415:20b]キャッチされなかった例外「NSRangeException」が原因でアプリを終了しています。理由:「***-[NSCFArrayobjectAtIndex:]:インデックス(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();
}
}
}
何か案は???
ありがとう
Jk