Re: (no subject) - NSOutlineView
Re: (no subject) - NSOutlineView
- Subject: Re: (no subject) - NSOutlineView
- From: Nick Zitzmann <email@hidden>
- Date: Fri, 16 Mar 2007 18:32:42 -0600
On Mar 16, 2007, at 6:01 PM, Orr Philip wrote:
If I've got an array of objects to be displayed and one of those is
an array of more objects, clicking on the arrow to the left reveals
a list of those said objects but how does the application know what
values it is being asked to display.
The key difference between NSOutlineView and NSTableView is while
NSTableView deals with row indices, NSOutlineView displays "items" in
each row. An item can be whatever you want it to be - NSStrings,
NSArrays of NSStrings, custom objects, or a combination of objects of
different classes. The only catch is an item can appear only once in
the view.
The three key data source methods are:
-outlineView:child:ofItem: (returns the child item of a parent item;
if the parent item is nil then it's asking for root items)
-outlineView:numberOfChildrenOfItem: (returns the number of children
of an item, if any; if the parent item is nil then it's populating
the root, like -numberOfRowsInTableView:)
-outlineView:objectValueForTableColumn:byItem: (this is just like the
NSTableView -tableView:objectValueForTableColumn:... data source method)
So, if you have an item that is an NSArray, and the user expands it,
the view first calls -outlineView:numberOfChildrenOfItem:, and your
app would probably return [item count] in this case. Then -
outlineView:child:ofItem: is called, and you return the object at the
given index in the NSArray. Finally, -
outlineView:objectValueForTableColumn:byItem: is called, and there
the app returns the object that actually gets displayed.
Nick Zitzmann
<http://www.chronosnet.com/>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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