5

I have an array of images, and two nib files. One nib file has a window that displays the images in an NSTableView. The other nib has a window that draws the array of images into an NSView, and also draws a highlight over the images that are selected.

The array of images is controlled by an NSArrayController. I'm having trouble getting the two nibs to share the NSArrayController. I would have two separate NSArrayControllers bound to the same content, but I also want both nibs to share the controller's selection; that is, if you select an image in the table window, it also becomes selected in the other window.

Is there a standard way to do this?

Tom Dalling
  • 23,305
  • 6
  • 62
  • 80

1 Answers1

5

I would have two separate NSArrayControllers bound to the same content, but I also want both nibs to share the controller's selection; that is, if you select an image in the table window, it also becomes selected in the other window.

Is there a standard way to do this?

Have two separate NSArrayControllers bound to the same content and selection indexes.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
  • @peter Could you elaborate on how to connect the two NSArrayControllers? – wigging Feb 20 '12 at 06:48
  • @Gavin: You don't. You just bind both controllers' content and selection-indexes bindings to the same properties of the same object. – Peter Hosey Feb 20 '12 at 08:14
  • @PeterHosey Could you please check out my similar question and carry on the comments there http://stackoverflow.com/questions/9356863/document-xib-contains-two-windows-one-window-needs-to-be-a-preference-panel – wigging Feb 20 '12 at 08:19
  • @PeterHosey Could you please elaborate a little more your answer ? You send via the `init` methods the `content` and `selection indexes`, and then bind them to another `NSArrayController` ? – Colas Mar 20 '13 at 16:28
  • @Colas: You have two array controllers (one in each nib), and you bind the `contentArray` and `selectionIndexes` of both of them to the same two properties of a third object (probably the FO). – Peter Hosey Mar 20 '13 at 20:01
  • @PeterHosey But what is this object ? If it is an instance (in the 2nd nib) of an object pointing the right object (in the 1st nib), is it enough ? Or, do we have to add observers ? – Colas Mar 20 '13 at 23:44
  • @Colas: Like I said, usually the FO of both nibs. Whatever object owns the content array (and, because both array controllers will need it, the set of selection indexes). – Peter Hosey Mar 21 '13 at 01:03