Re: NSTreeController, NSOutlineView and Core Data (again)
Re: NSTreeController, NSOutlineView and Core Data (again)
- Subject: Re: NSTreeController, NSOutlineView and Core Data (again)
- From: Quincey Morris <email@hidden>
- Date: Mon, 2 Mar 2009 15:02:16 -0800
On Mar 2, 2009, at 11:41, Peter Ferrett wrote:
I have Core Data objects bound to an NSOutlineView via a
NSTreeController. It is a schema that is common to other threads
on this group: one entity for the group, one entity for the leaf,
and a with the "children" relationship containing the groups/leafs
of the next level. The controller prepares the content. Everything
works fine, except that all objects appear at the root level. As
observed by others, I need to put a "parent == nil" fetch predicate
to prevent all objects appearing at the root level.
However ... with the fetch predicate is in place, the outline view
does not get updated until a new group/leaf with the "parent == nil"
predicate is inserted. When new leaf objects are inserted, they do
not appear in the outline view (until the next time that the an
object with the predicate is inserted).
There's an essential difference, in this setup, between what's going
on at the top level (the NSTreeController is in effect using the
result of a Core Data fetch request) and what's going on at all the
other levels (the NSTreeController is in effect monitoring the NSSet
that represents the "children" relationship of the non-leaf objects).
In the latter case, the NSTreeController monitors the relationship
using KVO.
The most likely reason that isn't working is that, when you insert a
new child object into the managed object context, you're not setting
the relationship in a KVO-compliant manner.
How are you establishing the parent/child relationship between
objects? Assuming you specified the parent and children relationships
as inverses, all of the following would be KVO-compliant (and
equivalent):
[child setValue: parent forKey: @"parent"];
child.parent = parent;
[[parent mutableSetValueForKey: @"children"] addObject: child];
[parent addChildrenObject: child]; // using Core Data's dynamic
accessor
but this would not:
[parent addObject: child];
_______________________________________________
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