I moved the code populating myListRoot to the "-init" method of MyDocument.m and now it works. I was earlier populating it in "-awakeFromNib".
I am so tried putting it back in -awakeFromNib followed by a call to [mOutlineView reloadData] - but this did not work. So I have my NSOutlineView showing me the text stored in my data root tree. But cant explain the above behavior. Thanks Hrishi On 12-Oct-2010, at 6:59 PM, Hrishikesh Murukkathampoondi wrote: > Thanks for the response. I am still having a little trouble. Here is what I > have done. I have set the keypaths and bindings of the NSTreeController and > NSOutlineView as below. > > myListRoot is a NSMutableArray containing NSTreeNode objects. I point the > content array binding of the NSTreeController to this variable. My tree is > only one level deep for now (I am still testing it). I add nodes to my tree > in this fashion: > > NSTreeNode *tn = [NSTreeNode treeNodeWithRepresentedObject:[NSString > stringWithString:@"History"]]; > [myListRoot addObject:tn]; > > MyDocument is KVC compliant with regard to myListRoot. After adding nodes I > traversed the tree (simple for loop) and printed contents to check the data > is correctly added. > > I made the following bindings - > > NSTreeController: > Key paths: > -------------- > Children: childNodes > > Since the nodes in the tree are objects of type NSTreeNode childNodes is the > correct method to return children of a given node. > > Bindings: > ------------ > Content Array: File's Owner myListRoot > > > I believe with the above bindings I have correctly tied the NSTreeController > to my data. Is this correct? > > I have made the following bindings in IB to bind elements in NSOutlineView to > the NSTreeController. > > NSOutlineView: > Bindings: > ----------- > Controller Key: arrangedObjects > Selection Index Paths: selectionIndexPaths > > Table Column Bindings: > --------------------- > Controller Key: arrangedObjects > Model Key Path: representedObject > > I expect that the table will send "representedObject" message to each > NSTreeNode object to get the string to be printed in each cell. > > When I run this I dont see the column in NSOutlineView populated. What am I > doing incorrectly? > > Hrishi > > > On 11-Oct-2010, at 1:50 AM, [email protected] wrote: > >> >> 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 protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
