Skip navigation.
 
mlRe: NSOutlineView with Multiple Core Data Entities
FROM : Jonathan Dann
DATE : Fri Jul 25 23:05:21 2008

Ah yeah, that bug is intentional!  The model uses an abstract TreeNode 
entity, which the tree controller is set to; however when you want 
concrete LeafNode and GroupNode entities (or sub-entities thereof) you 
need to create your own -add: methods so you can insert the correct 
entity into the tree.  As the tree controller has its entity set to 
TreeNode (abstract, so it can work will all sub-entity types), when 
calling -add: and addChild: it simply tries to insert an abstract 
entity.  Only the GroupNode responds to -isSpecialGroup, hence the 
exception.

I put those buttons, linked to -add: and -addChild:, in the project to 
emphasise that these no longer work when you want a non-trivial tree 
structure with multiple entities in the same tree.

What I do for the case you want is have an -insertGroupNode: method 
which creates the correct entity and inserts it into the tree at the 
index path you want.  For the default groups I do that in code, 
setting their -displayNames and setting -isSpecialGroup to YES so that 
the NSOutlineView delegate method -outlineView:isGroupItem: can 
interrogate the all the GroupNodes and will draw it in the correct way 
(like MAILBOXES, etc) when -isSpecialGroup returns YES.

In a shipping app I'd bracket such calls (when you don't know what 
type of node your dealing with) with a -respondsToSelector: or -
isKindOfClass: call.

Sorry for the confusion. Hope this clears it up.

Jonathan

www.espresso-served-here.com

On 25 Jul 2008, at 21:30, Garrett Bjerkhoel wrote:

> Here is a rough sketch of my datamodel. If you like I can take a 
> screenshot and post a link to it.
> Client
> ---Project
> ----Todo
> Writeoff
> ---Item
>
> By each entity having its own group, I am refering to say Mail.app 
> how it has "MAILBOXES", then "REMINDERS", or in iTunes "DEVICES", 
> and "LIBRARY". My intention was to have multiple group nodes as well 
> as multiple child nodes.
>
> On regards to your project, here you go:
> Once it loads, nothing is clickable :(
>
> In the debugger, this is what it says:
> 2008-07-25 12:35:01.031 SortedTree[1526:10b] *** -[ESTreeNode 
> isSpecialGroup]: unrecognized selector sent to instance 0x133d20
>
> On Jul 25, 2008, at 12:33 PM, Jonathan Dann wrote:
>

>>
>> On 25 Jul 2008, at 17:21, Garrett Bjerkhoel wrote:
>>

>>> I have a NSOutlineView hooked up to a NSTreeController, which has 
>>> multiple entities inside of it. I would like to know how to set it 
>>> up having each entity having its own "group". I have downloaded 
>>> Jonathan Dann's example, which compiles but freezes. I can see how 
>>> his Core Data model works, but I already have mine set.
>>>

>> Haha! That's great, sorry about that. I'm interested to know where 
>> it freezes, can you tell me more so I can fix it, please!
>>
>> Can you explain what you model looks like in a little more detail, 
>> and what you mean by each entity having its own group.  Do you want 
>> a single group node entity or multiple group nodes as well as 
>> multiple child node entities?
>>

>>> Do I need to have both of my entities have a parent entity in 
>>> which my NSTreeController reads from that one parent entity?
>>>

>>
>> If I understand you correctly, the general concept it to have a 
>> single abstract "TreeNode" entity.  This is the entity that the 
>> tree controller concerns itself with, you then can make as many 
>> concrete entities as you like that inherit from your abstract one.
>>
>> Jonathan
>>
>> www.espresso-served-here.com

>

Related mailsAuthorDate
mlNSOutlineView with Multiple Core Data Entities Garrett Bjerkhoel Jul 25, 18:21
mlRe: NSOutlineView with Multiple Core Data Entities Jonathan Dann Jul 25, 21:33
mlRe: NSOutlineView with Multiple Core Data Entities Garrett Bjerkhoel Jul 25, 22:30
mlRe: NSOutlineView with Multiple Core Data Entities Jonathan Dann Jul 25, 23:05