Re: Duplicate rows appearing in outlineview after creating new Entity in moc, why?
Re: Duplicate rows appearing in outlineview after creating new Entity in moc, why?
- Subject: Re: Duplicate rows appearing in outlineview after creating new Entity in moc, why?
- From: Jonathan Dann <email@hidden>
- Date: Thu, 17 Jul 2008 15:58:48 +0100
Yeah come to think of it I saw this behaviour when adopting the
mediator pattern in my app. In the NSPersistentDoc tutorial you can
create a Dept. object just using NSObjectController, then bind your
array contorller's contentSet binding to the object controller's
dept.employees keypath (or whatever they recommend). I tried to do
the same but with NSTreeController and had the same problems.
I'd file a bug if I were you. I now populate my tree controller by
binding it only to the MOC, and the problem disappears. So even
though I have my Dept. object, which has a bunch of employees in a to
many relationship I still fetch the tree data direct from the
context. This approach may not work for what you describe as the
tree you view seems to depend on another selection.
Jon
On 17 Jul 2008, at 00:34, Sean McBride wrote:
Jon,
Thanks for your reply. My fetch predicate was already "parent ==
nil".
I have narrowed this down to the fact that my treecontroller has its
'contentSet' binding set. If I remove that binding, duplicates no
longer appear.
I have created a very simple test app to illustrate:
<http://www.rogue-research.com/vtk/TreeTest.zip>
It's a master-detail interface. The master is a tableview/
arraycontroller on the left, the detail is an outlineview/
treecontroller
on the right. The treecontroller's 'contentSet' binding is bound to
'arrayController.selection.someRelationship'.
If someone would care to try:
- launch the app
- click 'Add Family'
- click 'New Folder'
- expand the folder's disclosure triangle
- (keep the folder selected)
- click 'New Person'
The new person appears both in the folder and at the root of the
outlineview. Remove the contentSet binding and the problem goes away.
It's only 50 lines of code. I don't get it.
Cheers,
Sean
On 7/16/08 1:44 PM, Jonathan Dann said:
The duplicate problem is likely fixed by giving the tee controller a
fetch predicate in IB. Set the predicate to something like
parent==nil. This will obviously depend on what you've called your
'parent' property.
I've blogged about doing this with drag and drop in core data and
non-
core data apps.
http://espresso-served-here.com
HTH
Jon
On 15 Jul 2008, at 22:59, "Sean McBride" <email@hidden>
wrote:
Hi all,
I have an outlineview populated by binding to a treecontroller. It
displays CoreData entities of type "Person". "Person" has 'parent'
and
'children' relationships. Displaying everything works fine.
Now the outlineview must support drops. In my windowcontroller, I
implement outlineView:acceptDrop:item:childIndex: and look for my
custom
pasteboard type. If it's there, I need to create a new "Person"
entity. How should I do this?
I have tried:
a) [myTreeController add:nil];
b) Person* person = [myTreeController newObject];
[person setParent:...];
c) Person* person = [NSEntityDescription
insertNewObjectForEntityForName:@"Person"
inManagedObjectContext:moc];
[person setParent:...];
In all cases, the outlineview shows 2 of the new person. The
problem is
not on the model side, since if I close and reopen the window,
only 1
new person is there.
Thanks,
--
____________________________________________________________
Sean McBride, B. Eng email@hidden
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
_______________________________________________
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:
@gmail.com
This email sent to email@hidden
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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