views:

15

answers:

1

Hello,

I want to bind to a NSTreeController's selectionIndexPaths programatically by doing the following (so that I can get a string a selection and display in a text view)

[activePDFView bind:@"name" toObject:treeController withKeyPath:@"selectionIndexPaths.nodeName" options:options];

The tree controller is bound to a NSMutableArray that contains objects with the "nodeName" property. The object inside the NSMutableArray is KVC compliant for the property "nodeName" since I've implemented the proper accessors.

When I compile, I get the following message

'[<__NSArray0 0x1001698d0> addObserver:forKeyPath:options:context:] is not supported. Key path: nodeName'

I am not quite sure but is my binding correct?

Thanks.

+1  A: 

It looks like what you want to bind to is not selectionIndexPaths, but instead the selection binding. The selectionIndexPaths binding will return an array of NSIndexPath objects, which is typically only used when binding an outline/browser view's selection to the tree controller. selection actually returns a proxy object which can represent either a single or multiple selection, and passes through any KVC requests to the underlying selected object(s). It's defined in NSObjectController, which is a superclass of NSTreeController. In your case, you would want:

[activePDFView bind:@"name" toObject:treeController withKeyPath:@"selection.nodeName" options:options];
Brian Webster
Thanks a bunch. That fixed the problem.
David
David: Then you should mark the answer as accepted by clicking the checkmark.
Peter Hosey