views:

167

answers:

2

I'd like to have a 'Detail view' for when the user double clicks on a row, I'm just not sure how to get the data to the NSViewController, so it can display the content. I'm using CoreData and I can't think of a way to do this.

+1  A: 

Cocoa bindings.
Apple has a great tutorial about creating Master-Detail interfaces online.
The screenshots are a bit outdated if you are using Xcode 3.2, but it's not that different.

NSViewController has a representedObject property, which allows you to bind to the model object that you are currently displaying.

Edit: OK. My answer isn't that great because it's only half the truth.
While it shows how to bind your controls within the detail view, it does not provide a solution on how to bind the selection of the array controller to the view controller's representedObject.
I would be interested in a bindings-only solution to this problem.

weichsel
+1  A: 

There are a couple of steps you need to do here:

  1. Make sure the table view is driven by a NSArrayController and that your controller for the table view (either a window controller or a view controller, or whatever) has that NSArrayController bound to an ivar so that you access it.

  2. In your table controller set the double click action to a method in your controller and set the target to your controller.

  3. In the double click method you can access the row by requesting the -selectedObjects from the NSArrayController and that resulting NSArray should have only one element in it.

From there you can then create your detail view or whatever else you want to do with it. You can create a sheet and display it, open a modal window, etc.

Marcus S. Zarra
Thanks so much!
nanochrome