1
코어 데이터가 UITableView
입니다.deleteRowsAtIndexPaths가 UITableView를 고정시킵니다.
새 레코드를 삽입하거나 기존 레코드를 업데이트하면 모든 것이 잘되고 UITableView
업데이트가 자동으로 업데이트되지만 레코드를 삭제하면 UIView
이 다시로드 될 때까지 UITableView
가 고정됩니다.
누가 잘못되었는지 알고 있습니까?
- (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:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView endUpdates];
}
내가 기록을 삭제하고 내가 디스패치 큐의 모든 작품을 잘 제거하면 상황에 맞는
- (void)refreshData
{
dispatch_queue_t fetchQ = dispatch_queue_create("Data Fetch", NULL);
dispatch_async(fetchQ, ^{
// here I delete some records
dispatch_async(dispatch_get_main_queue(), ^(void) {
[self saveContext];
});
});
}
- (void)saveContext
{
NSError *error = nil;
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil) {
if ([managedObjectContext hasChanges] && ![managedObjectContext 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.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
}
행을 제거한 경우 self.tableview 최종 업데이트를 시도 했습니까? 그러면 애니메이션이 끝날 수도 있습니다. 그냥 생각한 것 –
시작과 끝 업데이트가 쌍으로 호출되지 않는 것처럼 들립니다. 귀하가 성명서 옆에있는 각각의 부름을 기록하려고 시도 했습니까? 그리고 그들이 올바른 순서와 쌍으로 생기면 로그에서 보았습니까? – NSSplendid
@NSSplendid 먼저 일부 중단 점을 설정하면 controllerWillChangeContent에 도달합니다. 그런 다음 deleteRowsAtIndexPaths를 찾습니다. 결국 그것은 controllerDidChangeContent에 도달합니다. 올바른 질서처럼 보입니다. – robbert0