How do I share an NSArrayController between two nib files?
Asked Answered
Y

1

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?

Yarak answered 18/5, 2010 at 0:40 Comment(0)
H
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.

Helen answered 18/5, 2010 at 4:49 Comment(7)
@peter Could you elaborate on how to connect the two NSArrayControllers?Cirrose
@Gavin: You don't. You just bind both controllers' content and selection-indexes bindings to the same properties of the same object.Helen
@PeterHosey Could you please check out my similar question and carry on the comments there #9357363Cirrose
@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 ?Erv
@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).Helen
@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 ?Erv
@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).Helen

© 2022 - 2024 — McMap. All rights reserved.