CoreData: NSManagedContext not updating NSArrayController in UI
CoreData: NSManagedContext not updating NSArrayController in UI
- Subject: CoreData: NSManagedContext not updating NSArrayController in UI
- From: Marc Monguio <email@hidden>
- Date: Mon, 21 Nov 2005 00:59:58 -0800
This is the picture of my problem I'm facing:
I'm trying to update the main moc (NsManagedObjectcontext *) with
the new values inserted from another moc in another thread. I want an
NSArrayController to show the moc's new registered values in the
interface
(Note: both mocs share the same nsstorecoordinator)
What I do is catch the "NSManagedObjectContextDidSaveNotification"
notification sent by the second thread when doing a "moc:save". Then
"performSelectorOnMainThread" that calls a method where I register
the new inserted values:
- (void)handleMocWasSavedNotification:(NSNotification *)aNotification
{
[self performSelectorOnMainThread:@selector
(updateManagedObjectContext:) withObject:aNotification
waitUntilDone:NO];
}
- (void)updateManagedObjectContext:(NSNotification *)aNotification;
{
NSManagedObject *insertedObject;
NSSet *registeredObjects = [moc registeredObjects];
NSSet *insertedObjects = [[aNotification userInfo]
objectForKey:NSInsertedObjectsKey];
while ((insertedObject = [enumerator nextObject]) != nil) {
//this should register the insertedObject from the other thread to
the main moc
staleObject = [moc objectWithID:[insertedObject objectID]];
//to be sure I refresh it, it doesn't work either...
[moc refreshObject:staleObject mergeChanges:NO];
//to be sure I save, it doesn't work either...
[moc save:&error];
}
}
So what I'm doing is populate the main moc that is also used in the
NSArrayController. But the NSArrayController doesn't show the new
inserted values in the UI unless I ask for a fetch:
- (void)updateManagedObjectContext:(NSNotification *)aNotification;
{
[myArrayController fetch:self];
}
But, is "correct" way of doing it?
What I'm doing wrong in the former solution?
Thanks in advance for your answers.
regards,
Marc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden