views:

81

answers:

1

I'm setting up an edit window for a player to edit his user data. I've got all of the fields on the edit form bound to the appropriate Core Data entity (via an NSArrayController), and I've got an awakeFromNib method installed to handle calling the record, but I'm not sure what to put inside the method to get the record to display.

Ultimately, my goal with this is to set it up so that the application checks whether an entry exists for the user, and create one for him if there's no entry in the table.

+1  A: 

You should look at using a NSObjectController or NSArrayController rather than binding directly to the NSManagedObject. The controllers work properly with bindings and your data will display nicely and changes you make will be propagated via the controller to your NSManagedObject.

You can set the object used by the controller in your awakeFromNib. On NSArrayController use the setSelectionIndex:(NSUInteger) index message and then to avoid empty selection send it the setAvoidEmptySelection:TRUE message

Hope that helps.

Tom Duckering
Ah, guess I should have clarified a shade. I've got the entity bound to the array controller and the controller bound to the fields, as you've suggested. My goal here, ultimately, is to ensure that there is at least one entry in the entity so that I don't get `No Selection` appearing in all the fields.
Kaji
You can tell the NSArrayController to select one using an index and you can tell it to avoid having nothing selected. Check out the documentation.
Tom Duckering