これは障害/エラーではありませんが、例外として発生します。コア データを使用してオブジェクトを削除または挿入しようとすると、最初の挿入または削除で次のエラーが表示されます。
2012-04-09 18:57:32.201 SEA[7437:fb03] * -[UITableView _endCellAnimationsWithContext:] でのアサーションの失敗、/SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:1046 2012-04-09 18:57: 32.203 SEA[7437:fb03] CoreData: エラー: 重大なアプリケーション エラーです。-controllerDidChangeContent: の呼び出し中に、NSFetchedResultsController のデリゲートから例外がキャッチされました。無効な更新: セクション 0 の行数が無効です。更新後の既存のセクションに含まれる行数 (5) は、更新前にそのセクションに含まれる行数 (5) に、その数をプラスまたはマイナスした値と等しくなければなりません。そのセクションに挿入または削除された行の数 (1 挿入、0 削除)、およびそのセクションに移動された、またはそのセクションから移動された行数 (0 移動、0 移動)。userInfo (ヌル)
実際の tableView に新しい行または削除された行が表示されるため、これが発生する理由が少しわかりません。データベースには、正しい値とすべても表示されます。私が使用しているコードは次のとおりです。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[fetchedResultsController sections] count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[[fetchedResultsController sections] objectAtIndex:section] numberOfObjects];
}
さらにコードが必要な場合はお知らせください。
すべてのユーザーを表示する tableViewController 内。私は次のものを持っています:
(void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView beginUpdates];
}
(void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView endUpdates];
}
commitEditingStyle のコードは次のとおりです。
(void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
// Get context and user to delete
NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
User *userToDelete = [fetchedResultsController objectAtIndexPath:indexPath];
// Delete user from context
[context deleteObject:userToDelete];
// Save!
NSError *error = nil;
if(![context save:&error]){
// Handle the error..
}
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}