nothirst / TICoreDataSync

Automatic synchronization for Core Data apps, between any combination of Mac OS X and iOS: Mac to iPhone to iPad to iPod touch and back again.
https://github.com/nothirst/TICoreDataSync/wiki
807 stars 61 forks source link

Mac client and managedObjectContext changes not reflected to arrayController #96

Closed renzos closed 10 years ago

renzos commented 10 years ago

Hi guys, I'm developing the Mac Client of my iOS app The problem I have is related to the NSTableView refresh. I created an NSArrayController (Entity Mode) to make bindings, it works but when the Mac client receives changes from other clients, I save the managedObjectContext and force a tableView reload with no success. Here the code in the AppDelegate file:

-(void)documentSyncManager:(TICDSDocumentSyncManager
 *)aSyncManager 
didMakeChangesToObjectsInBackgroundContextAndSaveWithNotification:(NSNotificatio‌
​n *)aNotification{
     [self.masterviewcontroller.arrayController fetch:nil];
     [self.masterviewcontroller.tableView reloadData];
}     

I checked the SQLite file and it gets the updates but the arrayController not. The tableview refreshes on screen but it keeps the old data. If I close the app and start it again the tableview shows the new values. I use a custom table view cell with the NSTextFields binded with the interface builder.

renzos commented 10 years ago

I solved the problem from myself, hope it helps someone:

-(void)documentSyncManager:(TICDSDocumentSyncManager
 *)aSyncManager 
didMakeChangesToObjectsInBackgroundContextAndSaveWithNotification:(NSNotificatio‌
​n *)aNotification{
     [self.masterviewcontroller.arrayController setManagedObjectContext:[[NSApp delegate] managedObjectContext]];
     [self.masterviewcontroller.arrayController fetch:nil];
     [self.masterviewcontroller.tableView reloadData];
} 

so just call setManagedObjectContext before fetch. I didn't understand why I need to set it every time I need to force a fetch.