Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 30, 2006, 01:54 AM   #1
mduser63
macrumors 68040
 
mduser63's Avatar
 
Join Date: Nov 2004
Location: Salt Lake City, UT
Send a message via AIM to mduser63
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.
mduser63 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
core data binding not working Javajax Mac Programming 3 Jul 10, 2011 01:23 PM
core data and predicates - Problem! MACloop iPhone/iPad Programming 0 Jul 8, 2011 03:25 AM
Help Needed - Xcode 4 Options: Use Core Data Include Unit Tests Mitch1984 iPhone/iPad Programming 3 Feb 26, 2011 03:42 PM
Core data - binding related problem in NSNumberFormatter and NSDatePicker Monaj Mac Programming 8 Dec 16, 2010 04:12 PM
Direction on using Core Data and Data modeling mbabauer Mac Programming 11 Jun 2, 2006 04:52 AM


All times are GMT -5. The time now is 12:33 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC