これはNSFetchedResultsControllerDelegate
のドキュメントに与えられたテンプレートコードです:アップデート古い/新しいトップ/ボトムセルのbackgroundView挿入/ボトム/トップセルを削除
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
[self.tableView beginUpdates];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
switch(type) {
case NSFetchedResultsChangeInsert:
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex]
withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {
UITableView *tableView = self.tableView;
switch(type) {
case NSFetchedResultsChangeInsert:
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[self configureCell:[tableView cellForRowAtIndexPath:indexPath]
atIndexPath:indexPath];
break;
case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[self.tableView endUpdates];
}
このコードでは、デフォルトのグループ化されたスタイルのテーブルビューの更新そのセルはバックグラウンドビューでうまくアニメーションを変えます。最初のセルを削除すると、2番目のセルが最初の角になり、頂点が正方形から丸く変化します。
ただし、カスタムbackgroundView
のセルの場合、テーブルビューは同じ背景ビュー遷移を行いません。最初の行私は、適切な背景ビューの更新と素敵なアニメーションを復元するにはどうすればよい
を削除した後、最初の行
を削除する前に
:だから我々はこのようなものが表示されますか?
あなたは一番上に今ある行をリロードしてみてくださいました(使用した[self.tableViewのreloadRowsAtIndexPathsを<> withRowAnimation:<>])の行を削除した後? – lnafziger
この場合、行をリロードできます。しかし、多くの異なるケースがあります、私はそれらのすべてを扱う一般的な方法が欲しいです。今私は 'NSFetchedResultsControllerDelegate'メソッドで非常に複雑なコードを使用しています。グループ化されたテーブルビューのデフォルトのグループ化されたテーブルビューの素敵なアニメーションを適用するために使用できる魔法のトリガがあるかどうか、より明確な実装 – an0
画像をバックグラウンドビューに使用している場合は、自分自身を見て丸くする必要があります。 – fibnochi