Search code examples
objective-cxcode6cocoa-bindingsnsarraycontroller

How to bind NSArrayController to another NSArrayController were it has NSSet


I'm working on OS X app where I have a core data model like this:

Movies <--->>Theaters

I have bind an NSArrayController to the entity of the Movies in NSPopUpButton when I make a selections I should see the list of Theaters where the movie is playing.

In my Movies class header:

@property (nonatomic, retain) NSSet *theaters;

and my Theater class:

@property (nonatomic, retain) NSString * theaterName;

I tried to set the binding to "Content Set" but loads only the initial set and doesn't change the content when I switch the selection in the NSPopUpButton (Movies).

Any of you knows why always show the content related to the firs selection ?


Solution

  • The following works for me:

    First NSArrayController: set its entity to be Movie. Bind it to the NSManagedObjectContext.

    Second NSArrayController: set its entity to be Theatre. Bind it to the NSManagedObjectContext, and bind its Content Set to the moviesArrayController.selection.theatres.

    Then I have two popup: The first one has its content bound to moviesArrayController.arrangedObjects. Also its selectedIndex is bound to moviesArrayController.selectionIndex. The second popup is simply bound the the theatres controller.arrangedObjects.