How to Create & Add an Core-Data Object to an Existing Object Having an Optional To-One Relationship?
I cannot find any information anywhere (google, cocoadev, developer.apple) about managing an optional to-one relationship with core data and cocoa bindings with the exception of using a pop-up box. Using a pop-up box assumes the optional object already exists, but that's not how I want the process to work. I want to be able be able to select an existing object (User) in the table view and click an add button which would then cr开发者_如何学Goeate an new entity (Account) and assign the relationship to the selected User. In my model not all Users have an Account, and an Account is never created without having a User first.
Any ideas on how to do this?
I have tried to create a NSArrayController with the following:
Bind to: UserController Controller Key:selection Model Key Path: Account
I then bound a button to the -add function. When I do this I get:
[NSCFSet managedObjectContext]: unrecognized selector sent to instance 0x1001adea0
Please help I have spent days trying to figure this out.
I have learned that you must do this with code. I have extended NSArrayController and overridden the newObject method to assign selected object of other controllers.
精彩评论