Question

I've got an NSOutlineView acting as a source list for my application, and my data model is done with Core Data. I'd like to use bindings (if possible) to glue these things together as follows:

I have three main entities in my model, for sake of example let's call them "Stores", "Cars" and "People".

My goal is to have the outline view have 3 "groups" (expandable nodes, like PLAYLISTS in iTunes), each group representing and listing one of my entities, and also I've got three buttons at the bottom of my window to "Add Store", "Add Car", etc which I'd like to have wired up to perform that action.

So far in my window's nib I've got a TreeController which is bound to my NSManagedObjectContext instance of my window controller, but I can't figure out how to properly bind and populate the outline view from the TreeController.

Is this possible with bindings? I've seen one tutorial where a second managed object model is created, with entities for the outline nodes, but some comments on the article said this was a bad idea. I'm not really sure how to proceed, any help would be wonderful!

Was it helpful?

Solution

Try the Cocoa Bindings Programming topics: Providing Controller Content section

What I did was create custom classes for my entities, and added isLeaf properties to them. For the top level (Stores, Cars, People) I return no. For leaf nodes (a car, a person, etc) I return YES.

The top level needs to have a to-many relationship to the leaf nodes, I called this children.

In Interface Builder, I set the NSTreeController's mode to Entity, name: Groups. It's bound to the managedObjectContext. In the Key Paths I set the Children attribute to children, and Leaf to isLeaf.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top