Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mduser63

macrumors 68040
Original poster
Nov 9, 2004
3,042
31
Salt Lake City, UT
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.