Re: NSOutlineView question
Re: NSOutlineView question
- Subject: Re: NSOutlineView question
- From: Chris Hanson <email@hidden>
- Date: Wed, 20 Aug 2003 16:28:33 -0500
An NSOutlineView works just like an NSTableView in that it queries a
data source for the information to display. This data source can be
set programmatically or in Interface Builder, just like for an
NSTableView. However, because the information in an NSOutlineView is
hierarchical rather than linear, it can't ask for it by row, so instead
it's asked for by "item."
The nil item is the root of the outline. As necessary, an
NSOutlineView will ask its data source for:
* The number of child items an item has.
* Whether an item is expandable.
* The child item at a particular index "within" an item.
* The object value at a particular (item, table column) coordinate.
The trick is that you need to manage the items entirely by yourself.
Even though items have type "id" NSOutlineView really treats them as
opaque tokens; I don't believe it even retains them. The other trick
is that child items are accessed in order, so you can create them on
the fly.
What I do is create a simple OutlineItem adaptor class and instantiate
one for each row of your outline. My OutlineItem class does all the
work of tracking its children (if it has any) etc. and fits in between
my data model and the NSOutlineView. I then have a generic outline
data source object that just needs to (a) keep track of a root
OutlineItem and (b) know how to pass outline data source requests on to
the correct item.
Check out the documentation on the NSOutlineViewDataSource informal
protocol as well as the NSOutlineView class documentation for more
information. I looked at the same sample code you're looking at, as
well as this documentation, and did a couple hours of experimentation
to come up with the system I described.
-- Chris
--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Mac OS X Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
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.