Re: NSOutline and NSTreeController using bindings
Re: NSOutline and NSTreeController using bindings
- Subject: Re: NSOutline and NSTreeController using bindings
- From: "email@hidden" <email@hidden>
- Date: Sun, 10 Oct 2010 21:20:17 +0100
Regards
On 10 Oct 2010, at 19:55, Hrishikesh Murukkathampoondi wrote:
>
> NSOutlineView bindings -
> 1. "Content" bound to NSTreeController's "arrangedObjects"
> 2. "Selection Index Paths: to NSTreeController's "selectionIndexPaths"
>
> NSTableColumn bindings:
> 3. "Value" is bound to arrangedObjects.name
>
These look okay.
>
> I have read the class reference for NSTreeController and NSOutlineView but I still dont understand how the above works. Foe example, how does the NSOutlineView know which values are leaves?
>
> NSOutlineView class ref document describes how to implement the data source if using conventional data sources. How does it work with bindings?
>
> The above "special" format for the contents array is not discussed any where.
>
The example creates a single node with three children.
The 'special format' you refer is documented in NSTreeController. Its not the array that is important, it's the objects within in it.
In the example above we must presume that NSTreeController -childrenKeyPath has been set to @"children" (this may have been done in IB).
This way the controller knows which method to call to traverse the tree (there is also a -leafKeyPath method).
The contents array is an array of objects each of which acts as the root for a branch.
In this case the object is a single NSDictionary object.
This will be queried using -valueForKey:/-valueForKeyPath: which will ultimately invoke -objectForKey: on the dictionary.
Basically you supply a readymade tree and bind it to the NSTreeController.
Although an NSDictionary can be used for this purpose NSTreeNode is supplied specifically for this purpose.
Create an array of NSTreeNode instances that will act as your roots.
Then add your children to the roots as further NSTreeNode instances.
Your model object can be supplied as the -representedObject in which case the binding key path typically looks like @"arrangedObjects.representedObject.name"
An item in an NSOutlineView will be represented as an NSTreeNode (see the 10.5 release notes for this essential fact).
However the tree that is returned is the NSOutlineView's currently displayed tree.
Your NSTreeNode (or whatever representation you have employed) instance is the item's representedObject.
Hence to get to your model data you would invoke:
NSTreeNode *outlineNode = [outlineView itemAtRow:row];
NSTreeNode *myNode = [outlineNode representedObject];
id myNodelData = [myNode representedObject];
HTH
Jonathan Mitchell
Developer
Mugginsoft LLP
http://www.mugginsoft.com_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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