-->

Master-detail using bindings with TWO NSTableViews

2019-07-20 18:36发布

问题:

I have a list of objects displayed in an NSTableView (bound to an NSArrayController). When you select an object in that list I want to show a detail view in a second NSTableView. My object has an array property. I can't figure out how to wire the bindings for this. binding to NSArrayController's selection doesn't work, as that's a single object, and NSTableView expects to be bound to an array...

回答1:

Create a second NSArrayController and bind its contents to the first controller using a keypath of selection.<name of your object's array property>.

So, if your first table view is displaying objects of class Person and your Person class has a children property, you would bind the second array controller to selection.children.

You need a separate array controller for each array that you want to manage in a table view.