views:

120

answers:

1

I've got a window set up with two NSTableViews. In Core Data I have two entities set up, one of them containing members of the other, larger grouping (e.g. cars and manufacturers). I've got entry pages set up for each entity and they play nicely there (no faulting when trying to select from a many-to-one in a drop menu). What I'm trying to do now is take that one step further so that when I select a manufacturer in the main NSTableView, the list of cars related to that manufacuturer will appear in the second NSTableView.

I've tried using bindings similar to what I've done for the manufacturer popup button, feeding the value from the cars entity, however it's simply showing a list of all the car entries, regardless of which manufacturer I select. I don't see any options for a predicate to filter it, however, and if I set the binding's key path to manufacturer.cars, it shows a relationship fault. How can I filter what gets displayed in the child table?

+1  A: 

Have two NSArrayControllers. Bind the contentArray of the cars controller to the manufacturers controller; the controller key is selection (i.e., the selected manufacturer), and the model key path is that of the property containing the manufacturer's cars.

Then, bind the cars table view's columns to properties of the cars controller's arrangedObjects.

Peter Hosey
I'm trying this, but all it's doing is causing the edit pages to not display their content properly, and any selections on the master/children display to blip away right after being clicked. Is there a step along the way here that needs double-checking?
Kaji
Yes, check the model key paths carefully. They should look something like "selection.name" or "selection.brand". In fact, check all names: for instance, is the entity really called manufacturer and not manufacturers? Also, check the relationship in the data model: is cars a one-to-many relationship, is it required?
Elise van Looij
`selection` should be the controller key, not part of the model key path.
Peter Hosey