|Jun 30, 2006, 01:54 AM||#1|
Core Data and Bindings Problem
It might be hard to describe my problem well enough, but I'll try.
Say I've got a data model with two entities in it. One is called Person, and the other is called Address. Person has a few attributes like name, phone number, age, etc. It has one to-one relationship to an Address entity. Now Address also has a few attributes like street number, city, state and zip code and a to-one relationship to a person. All fine up to this point.
Now I want to create a user interface using IB and bindings to manage an array of Person entities. No problem, this is easy with a table view, an NSArrayController and some text fields to set the various attributes of the Person selected in the table. Here comes the problem. I want to have more text fields that set the attributes of the Address entity related to the currently selected Person entity. I can't for the life of me figure out how to get this to work.
What I've got right now (and it doesn't work) is an NSObjectController called Address Controller set to control an Address entity in the Attributes Inspector. In the bindings, the Controller Content is bound to the Person Array Controller with a Controller Key of "selection" and a model key path of "myAddress" (the name of the relationship from Person->Address). My reasoning (though it may be incorrect) is that this means that the NSObjectConroller has one object that it controls, and it is the object "pointed to" by the myAddress relationship of the currently selected Person where Person Array Controller is bound to the table used to do the selection. I've got the managedObjectContext binding for the Address Controller bound to File's Owner (MyDocument) with a blank Controller Key and a Model Key Path of managedObjectContext. This is the same thing that the Person Array Controller's managedObjectContext binding is set to. I'm not sure if this is right.
Now I have one text field called City (to keep it simple) that I want to display/edit the City attribute of the Address entity related to the currently selected Person. In the value binding for the text field I've got it bound to Address Controller with a Controller Key of selection and a model key path of "city". (I have tried using "content" for the Controller Key too, but it doesn't work.)
With the current set up, the text fields that are bound to direct attributes of Person work fine. They modify the respective attributes of the Person entity selected in the table view. Open/save works fine too. However, the text field for city is grayed out and says "No Selection" (if I change the Controller Key to "content" it becomes editable but it doesn't do anything ie. it doesn't affect the stored attributes of the currently selected Person's Address).
I *think* my problem is with bindings, but I suppose it could be with my Core Data model. I'm getting pretty frustrated trying to figure this out, so I wanted to ask about it.
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|Core Data help.||Ernie11||iPhone/iPad Programming||4||May 11, 2014 08:46 PM|
|Core data advice?||cpuin||Mac Programming||0||Sep 24, 2013 11:13 AM|
|Having an issue passing data between views with Core Data.||iJustinCabral||iPhone/iPad Programming||0||Jul 15, 2013 09:50 PM|
|Sqlite and Core Data||kimbebot||iPhone/iPad Programming||5||Jul 23, 2012 01:44 AM|
|Saving data from custom tablecells core data||luke3||iPhone/iPad Programming||0||Jul 14, 2012 06:09 PM|
All times are GMT -5. The time now is 04:22 PM.