NSCollectionView Master detail binding configuration

爷,独闯天下 提交于 2019-12-25 03:58:06

问题


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


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!