问题
I have the following models in my application.
Board
, holds a NSMutableArray propertylists
of typeList
belowList
, holds a NSArray propertycards
of type Card belowCard
, has a NSString propertyname
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:
arrangedObjectsselection - ** Model key path: lists
- ** Mode: Class
- ** Item prototype: List View Item
CardArrayController -> bound to ListArrayController
- ** Controller key:
arrangedObjectsselection - ** 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
回答1:
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
来源:https://stackoverflow.com/questions/24190299/nscollectionview-master-detail-binding-configuration