在多上下文核心数据方面苦苦挣扎,我会很高兴得到任何帮助。
同步操作完成后,调用此块:
[[SyncEngine sharedEngine]setFinishedSyncCompletionBlock:^{
//---setting FRC to nil did refresh tableview but it is kinda slow
// self.fetchedResultsController=nil;
[self loadRecordsFromCoreData];
[self.tableView reloadData];
}];
在这里我可以看到新的托管对象在上下文中。但是调用 [self.tableView reloadData]; 在此之后不会刷新我的 tableview,或者 (void)controllerDidChangeContent:(NSFetchedResultsController *)controller 不会触发。
- (void)loadRecordsFromCoreData {
NSLog(@"here loadRecordsFromCoreData");
[self.managedObjectContext.parentContext performBlock:^{
//---this is also a trial for resetting FRC
// [self.managedObjectContext reset];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Event"];
// Edit the sort key as appropriate.
fetchRequest.sortDescriptors = @[ [[NSSortDescriptor alloc] initWithKey:@"timeStamp" ascending:NO] ];
NSArray *objects = [self.managedObjectContext.parentContext executeFetchRequest:fetchRequest error:NULL];
NSArray *objectIDs = [objects valueForKey:@"objectID"];
[self.managedObjectContext performBlock:^{
NSArray *objects = [self.managedObjectContext objectsWithIDs:objectIDs];
// self.fetchedResultsController.managedObjectContext = self.managedObjectContext;
NSLog(@"objects: %lu", (unsigned long)objects.count);
}];
}];