セルをクリックし、背景のコアデータのリフレッシュが発生すると、セルの選択が解除されます。調査の後、2つの同一のNSIndexPathでNSFetchedResultsChangeMoveが呼び出されたときに、セルを選択したままにする方法はありますか?
をcontroller:didChangeObject:atIndexPath:forChangeType:newIndexPath:
の私NSFetchedResultsControllerDelegate
の実装は、NSFetchedResultsChangeMove
のタイプと呼び出さなくindexPath
とnewIndexPath
(すなわち同じ行/セクション値)同一です。
NSFetchedResultsChangeUpdate
タイプは呼び出されません。
controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:
の実装は、Appleのマニュアルで提供されている典型的なものです。
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {
...
switch(type) {
...
case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
へ:
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {
...
switch(type) {
...
case NSFetchedResultsChangeMove:
if (indexPath.section != newIndexPath.section || indexPath.row != newIndexPath.row) {
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
}
break;
}
}
私の問題を解決するだろう私からの切り替えと考えています。
私の質問は:この修正プログラムは正しいですか、または私の更新プログラムがNSFetchedResultsChangeMove
タイプの理由を説明することができるものがありますか?