Search code examples
cocoacocoa-bindingskey-value-observingnsarraycontrollernscollectionview

NSCollectionView Master detail binding configuration


I have the following models in my application.

  • Board, holds a NSMutableArray property lists of type List below
  • List, holds a NSArray property cards of type Card below
  • Card, has a NSString property name

The relationship is thus Board --> to-many List --> to-many Card

I have a NSCollectionView based master-detail interface, where I want to display Boards in the master and its corresponding Lists+Cards in the detail view.

The master interface is fine, the elements Board are displayed nicely.

Bindings are setup like so:

BoardArrayController -> bound to File's owner

  • ** Model key path: boards
  • ** Mode: Class
  • ** Item prototype: Board View Item

ListArrayController -> bound to BoardArrayController.

  • ** Controller key: arrangedObjects selection
  • ** Model key path: lists
  • ** Mode: Class
  • ** Item prototype: List View Item

CardArrayController -> bound to ListArrayController

  • ** Controller key: arrangedObjects selection
  • ** Model key path: cards
  • ** Mode: Class

The master collection view has the Content bound to BoardArrayController

  • ** Controller key: arrangedObjects

The detail collection view has the Content bound to the BoardArrayController

  • ** Controller key: selection
  • ** Model key path: lists

View item prototype

Any view element in the prototype views (those that are added with the NSCollectionView) have the following info

  • ** Bound to: Board View Item (master) or List View Item (detail)
  • ** Model key path: representedObject followed by .property

Problem

The detail interface is not updated when I click a board in the master view. I expect a new set of lists+cards being displayed. It is only the one loaded at startup which is being displayed.

Questions

Is this a NSCollectionView selection problem or a binding problem?

Hint: I think it's a binding problem. Because it works, if in my controller I observe masterView.selectionIndexes and bind an IBOutlet to detailedView. Then in observeValueForKeyPath:ofObject:change:context: I manually call detailedView:setContent:.

Edit: updated setup description in accordance to the answer in Cocoa Bindings for hierarchical model


Solution

  • Finally got an answer from the cocoa-dev mailing list (thanks Willeke).

    Solution

    The master view selectionIndexes is bound to BoardArrayController. With Controller Key selectionIndexes.

    The detailed view content should then be set to ListArrayController and Controller Key Path arrangedObjects