Re: Understanding NSOutlineView...
Re: Understanding NSOutlineView...
- Subject: Re: Understanding NSOutlineView...
- From: email@hidden (Simon Fraser)
- Date: Tue, 16 Dec 2003 18:45:12 -0800 (PST)
- Organization: AOL
Ron Ballesteros wrote on 16/12/03, 4:31 pm:
>
I'm trying to understand how to implement the NSOutlineView and I'm
>
having a hard time grasping how to implement the datasoure methods. I
>
understand how to implement an NSTableView datasource methods quite ok
>
but the NSOutlineView I can't seem to grasp.
>
>
The object models that I want to show essentially is an array and each
>
array item in turns has 5 items which can be viewed as its 5 children.
>
>
I can't seem to grasp what the (id)item is? I read that the item is an
>
object containing the data for
>
one row....
>
for example the method: outlineView:child:ofItem. this appears to be
>
requesting for the child of
>
item but I'm not sure what item is, is this an object in the parent
>
array or one of the 5 children.
The "item" id is just a cookie. It's a cocoa object that you give back
to Cocoa for each item, and then cocoa hands back to you when asking
for children, and when drawing.
There's pretty much no restriction on what the item can be (Cocoa
doesn't call any methods on it), other than the fact that it has to
stick around for the life of that outliner item; you can't hand back a
tempororary, autoreleased object, for example. Often, these items are
stored in an NSDictionary to keep them around.
Note that when cocoa passes nil as the 'item' to a method, it's
referring to the root object. Use the root of your data structure,
which you presumably has as a member variable somewhere.
The data structure that probably maps most easily to the outliner
model is a tree, where each item in the tree has an NSArray*
of children. You just pass the items around in the "id",
child:ofItem: just does an array lookup, and isItemExpandable:
just asks if there are any items in the child array.
The somewhat confusing part of the outliner datasource is what
to return from "outlineView:objectValueForTableColumn:byItem:".
This should be something displayable (say an NSString), rather than
one of your cookies.
HTH
Simon
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.