Search code examples
objective-ccocoacocoa-bindingsnibnsdocument

Binding to array controller in another nib for inspector window


  • Binding a popup menu to an array controller with the path selection.type works fine.
  • Binding a popup menu to a document controller with the path currentDocument.arrayController.selection.type works one way only (changes in selection are not propagated to the popup menu).

How can one achieve inspector-window-like functionality by binding a popup menu to the appropriate array controller depending on the document in focus?


Solution

  • Here's an (ugly) workaround for anyone struggling with this: subclass NSArrayController so that its selection always returns all its contents, keep track of the selected items yourself in an NSMutableSet, and bind the array controller's content set to that. (For some reason, binding the content set of an array controller works across the nibs, though binding the selection indices of a popup menu doesn't.)