私のコアデータをバックアップしようとしていますUITableViewに並べ替え機能があります。これらのデリゲートとコアデータのテクニックを実装した後here私は奇妙な動作を発見しました。編集ボタンをタップした後、並べ替えアイコンがうまく表示され、それをタップすると影が現れますが、別の行に移動しようとすると突然フォーカスが失われ、セルがその場所に戻ります。誰もがこの問題の原因を知っていますか?ここで並べ替え時に現在の位置からUITableViewCellをドラッグできない
は、ここで問題
http://www.youtube.com/watch?v=ugxuLNL7BnU&feature=youtu.be
を示すビデオは私のコードは、私は以下のコードとちょうど空の実装が、問題を試してみました-tableView:moveRowAtIndexPath:toIndexPath
で
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
ですまだ存在するので、私はこれが問題ではないとは思わない。
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
_changeIsUserDriven = YES;
NSUInteger fromIndex = sourceIndexPath.row;
NSUInteger toIndex = destinationIndexPath.row;
NSMutableArray *newsArray = [[self.fetchedResultsController fetchedObjects] mutableCopy];
News *news = [self.fetchedResultsController.fetchedObjects objectAtIndex:fromIndex];
[newsArray removeObject:news];
[newsArray insertObject:news atIndex:toIndex];
int i = 1;
for (News *n in newsArray) {
n.displayOrder = [NSNumber numberWithInt:i++];
}
[self saveContext];
_changeIsUserDriven = NO;
}
FetchedResultControllerデリゲート
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
if (_changeIsUserDriven) {
return;
}
[self.tableView beginUpdates];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type
{
if (_changeIsUserDriven) {
return;
}
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
{
if (_changeIsUserDriven) {
return;
}
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
{
if (_changeIsUserDriven) {
return;
}
[self.tableView endUpdates];
}
'tableView commitEditingStyle:forRowAtIndexPath:'を実装し、 'UITableViewCellEditingStyleInsert'ケースを実装してデータソースを更新し、実際に行(または' reloadData')を移動しましたか? – lnafziger
コアデータとfetchedResultControllerを使用しており、すべての保存部分は ' - (void)tableView:moveRowAtIndexPath:toIndexPath:' – sarunw
で終了しました。もっとコードが追加されました: – lnafziger