views:

215

answers:

1

(Abstract: bindings work in code, but not in IB)

I have a window managed by a NSWindowController. To the left of the window is a source view. To the right is a table view showing the elements of the currently selected source.

I have set up a NSTreeController within my window XIB. I want its contents to be used for the source view. It's selection will drive the table view.

I am trying to split this up using NSViewControllers. One view controller will load a NIB containing the source view. Another view controller will load the table view.

Seeing that I need access to the NSTreeController within the source view controller, I have set it to be the view controller's representedObject. (Actually for this setup to be done by the time awakeFromNib is called on the view controller, I have turned representedObject into an IBOutlet).

All works fine when I wire my source view up in code:

[outlineView bind:@"content"
   toObject:sources
   withKeyPath:@"arrangedObjects"
    options:nil];
[outlineView bind:@"selectionIndexPaths"
   toObject:sources
   withKeyPath:@"selectionIndexPaths"
    options:nil];
[[outlineView tableColumnWithIdentifier:@"Title"] bind:@"value"
             toObject:sources
             withKeyPath:@"arrangedObjects.title"
              options:nil];

I am however unable to reproduce this using Interface Builder. Thing is, here the "controller key" textfield is grayed out. Thus I bind column's "value" to the file owner using a model keyPath of "representedObject.arrangedObjects.title". This does not show the desired behavior. Actually an exception is thrown: -[NSProxy doesNotRecognizeSelector:_mutatingNodes] called!

How can I use representedObject in IB? Can I create a controller in IB which acts as proxy to representedObject? Could I set-up a tree controller in the source view XIB which during NIB loading gets swapped out for the representedObject?

+1  A: 

I moved away from using representedObject. It appears that is meant only for model objects.

I now pass in my tree controller using a custom outlet. I continued setting up and tearing down the bindings in code.

Pierre Bernard