Re: CoreData: NSManagedContext not updating NSArrayController in UI
Re: CoreData: NSManagedContext not updating NSArrayController in UI
- Subject: Re: CoreData: NSManagedContext not updating NSArrayController in UI
- From: Jim Correia <email@hidden>
- Date: Mon, 21 Nov 2005 07:17:22 -0500
On Nov 21, 2005, at 3:59 AM, Marc Monguio wrote:
- (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];
}
}
If you have simply inserted objects in another moc, then they aren't
stale in this moc, since they've never been registered. Your loop
should be using objectRegisteredForID: and only refreshing those (so
as to not pull in objects that no one wasn't already paying attention
to.
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];
}
As far as I know, this is the only way to get your controller to
react to insertions/deletions in another moc.
Jim
_______________________________________________
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