Re: Fun (or not) with NSArrayControllers and CoreData.
Re: Fun (or not) with NSArrayControllers and CoreData.
- Subject: Re: Fun (or not) with NSArrayControllers and CoreData.
- From: Daniel DeCovnick <email@hidden>
- Date: Fri, 31 Jul 2009 10:33:25 -0700
Try this:
-- Add an "allDescendantJobs" Core Data to-many relationship to the
Folder entity in your Core Data model. Set its delete rule to Nullify.
-- Add a "rootFolder" Core Data to-one relationship to the Job
entity, and make it the inverse of "allDescendantJobs". Set its
delete rule to Nullify.
-- Whenever you add a Job object to a Folder, also set the
rootFolder property:
addedJob.rootFolder = [parentFolder ... find its root folder
recursively or whatever ...]; // this is KVO compliant for both ends
of the relationship
-- Bind a NSArrayController in entity mode to the
"allDescendantJobs" property of whatever represents the selection
in the Folders outline view.
-- Bind the Jobs table view to this array controller.
Now it should work. The only problem is going to be that the user
interface may update for *each* Job object that's added/removed,
which is less than optimal if you're updating a lot of them. And
you're keeping an extra pair of relationships in the persistent
store. If you need to avoid either of those things, you're going to
have to work harder.
Thanks for the help so far, I think I'm about 90% there; there's still
something wrong with a binding somewhere. If I unbind the Content Set
of the JobArrayController (so I see all Jobs) adding some extra table
columns showing the Folder name and root Folder name, adding and
removing Jobs works fine (the data shows up in the table, and the
Folder and root Folder name are correct) using the following methods
(on my window controller):
-(IBAction)newJob:(id)sender
{
id folder = [self currentFolder];
CCCEJob *newJob = [NSEntityDescription
insertNewObjectForEntityForName:@"CCCEJob" inManagedObjectContext:
[self managedObjectContext]];
[folder addJobsObject:newJob];
newJob.rootFolder = [newJob getRootFolder];
}
-(id)currentFolder
{
if ([[folderTreeController selectedObjects] count]!= 0)
{
return [[folderTreeController selectedObjects] objectAtIndex:0];
}
else return nil;
}
and on Job:
-(id)getRootFolder
{
id cursor = [self folder];
while ([cursor parent])
{
cursor = [cursor parent];
}
return cursor;
}
But if I have the Content Set of JobsArrayController bound to
FolderTreeController with Controller Key: selection and Model Key
Path: allDescendantsJobs, nothing shows up in the table. I've double
and triple-checked the model to make sure the inverse relationships
are set properly.
Thanks again for the help.
-Daniel
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden