Re: Model change behind NSTreeController's back
Re: Model change behind NSTreeController's back
- Subject: Re: Model change behind NSTreeController's back
- From: Sam Stigler <email@hidden>
- Date: Wed, 9 May 2007 23:46:02 +1000
So, I'm still having trouble getting my NSTreeController /
NSOutlineView combo to update. I think part of the reason is that I
have a complicated data structure (see http://homepage.mac.com/
sstigler1985/iDocumentModel.png for the model), with completely
different classes (although both falling under the same abstract
class of "Node" as the top-level and leaf nodes (ideally-speaking) in
my two-level outline view. In the model, OutlineGrouping is supposed
to be the top-level node, and subclasses of type Item are supposed be
the children (all leaves).
The tree controller has always been set to automatically prepare
content, but until recently I had its entity set to OutlineGrouping.
In those cases, when I added any entity of type Item, it wouldn't
update. (I feel I should note here that all of my entities are
NSManagedObject subclasses, but with minimal customization.) Anyhow,
on a whim (out of desperation) I decided to change the tree
controller's entity to Node, the abstract class encompassing all of
the entities in my data model. As soon as I did that, any Item added
instantly showed up in my outline view. My question for you is,
why? Now that I know it's not a KVO problem (at least I don't think
so...), what do I need to do in terms of modifying my data model, my
tree controller settings, etc. to get newly-added Items to show up as
children of their respective OutlineGroupings?
My current NSTreeController settings are:
Entity Name: OutlineGrouping
boxes are checked for everything but "always use multiple values marker"
Children key path: group
Count key path: <empty>
Leaf key path: isLeaf (a custom method I implemented; returns YES
for Node, for OutlineGrouping, uses the following code.)
Some of the code in the OutlineGrouping class:
-(int)count
{
NSSet *myChildren = [NSSet setWithSet:[self valueForKey:@"group"]];
return [myChildren count];
}
-(BOOL)isLeaf
{
return ([self count] == 0);
}
Many thanks for any ideas you can give me,
Sam
On May 6, 2007, at 3:40 AM, Conor wrote:
It should update automatically when you call
insertNewObjectForEntityForName:inManagedObjectContext; so I would
double
check your interface builder settings for the tree controller.
Check out /Developer/Examples/CoreData/OutlineEdit especially the nib
settings for the tree controller for an excellent example. They are
actually
using "[outlineTreeController add:sender];" but it will work with
insertNewObjectForEntityForName:. Check out dedentNote: and
indentNote:
methods, you will notice they only modify then NSManagedObject in
Core Data
and the tree controller updates itself as well as the outline view.
Regards,
Conor
http://www.bruji.com/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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