Re: Understanding NSOutlineView...
Re: Understanding NSOutlineView...
- Subject: Re: Understanding NSOutlineView...
- From: Chris Hanson <email@hidden>
- Date: Tue, 16 Dec 2003 20:50:16 -0600
On Dec 16, 2003, at 6:31 PM, Ron Ballesteros wrote:
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....
Not necessarily. The best way to think of an (id)item in an
NSOutlineView is that it's an opaque token representing a single item
in the outline.
It could be an actual model object, it could be an adaptor object of
some sort, whichever. You have to manage the correspondence between an
(id)item (including the nil (id)item) and one of your model objects
yourself. Note that you'll also have to manage memory for these
yourself; at least in Jaguar and earlier, NSOutlineView wouldn't retain
them for itself.
What I've done in the past is create an OutlineDataSource class that
acts as an NSOutlineView's dataSource. It then manages a bunch of
OutlineItem objects that are passed to and received back from
NSOutlineView; these OutlineItem objects manage their own child
OutlineItems, and so on.
In terms of manipulating individual items via an NSOutlineView, it will
send appropriate messages to its OutlineDataSource. This then
determines the appropriate item and does whatever it needs to the item.
You can leverage key-value coding here by having the OutlineDataSource
just use -valueForKeyPath: and -setValue:forKeyPath: to manipulate the
OutlineItem, and then have the OutlineItem override those to forward
them on to their represented object.
-- Chris
--
Chris Hanson <email@hidden>
Weblog:
http://www.livejournal.com/users/chanson/
Resume:
http://bdistributed.com/people/cmh/resume.html
Looking for work developing Java or Mac OS X applications
_______________________________________________
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.