- 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 funct开发者_Python百科ionality by binding a popup menu to the appropriate array controller depending on the document in focus?
Are they the same array controller, or is the Inspector window using a separate array controller that happens to be fed by the same array?
Two separate array controllers will have two separate selections. To fix that, give the same object that owns the ultimate array a second property for an NSIndexSet for the selection, and bind both array controllers' selectedIndexes
to that property.
It may seem slightly silly to use an NSIndexSet for a pop-up menu's single (not multiple) selection, but array controllers are generic like that.
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.)
精彩评论