Re: Programmatically binding Core Data to dynamic NSTableColumns
Re: Programmatically binding Core Data to dynamic NSTableColumns
- Subject: Re: Programmatically binding Core Data to dynamic NSTableColumns
- From: Quincey Morris <email@hidden>
- Date: Wed, 17 Mar 2010 13:21:05 -0700
On Mar 17, 2010, at 10:59, Michael LaMorte wrote:
> I have a Core Data application with two entities: Item and Entries. Item has a dataType string variable. Item has a to-many inverse relationship to Entries. Entries has two variables: stringData and numberData.
>
> I'm programmatically creating an NSTableColumn for each Item. The cell type of the column is defined by the Item's dataType variable. This part is working.
>
> The goal is for each Item to have a column, and when clicking an Add New Entry button, a new Entry is created for each Item. The interface would add one row, with the value bound to the corresponding stringData or numberData for the Entry for that Item.
>
> Right now, the Add New Entry button/method loops through the Items and creates a new Entry for each... that's working okay. Where I'm having problems is figuring out the bindings to properly display the columns. The bind statement I'm using is:
>
> [itemColumn bind:@"value" toObject:entryArrayController withKeyPath:@"arrangedObjects.numberData" options:nil];
>
> (It's in an if statement, so it binds to either numberData or stringData as appropriate.)
>
> This results in 1 row being added for each Item, and the entire row is bound to the same value. So if I have 6 Items, I correctly have 6 columns (one for each Item) but clicking Add New Entry it incorrectly generates 6 rows, one for each Item.
You seem to be saying that each Item has its *own* Entries, but you fail to say what ties the Entries together that need to be shown in the same row.
You also don't say what your entryArrayController's content is. If it's simply using the set of Entries, then of course you're going to get 6 rows if you add 6 entries.
Either the Items need to share Entries, so that each of the Entries corresponds to its own row in the table, or you need *something* that represents the row (with different Entries for each of the Items).
Incidentally, it's usual for entities to be singular rather than plural (Entry rather than Entries) and for to-many relationships to be plural (such as item.entries). The fact that you called your entity Entries suggests that you're not quite sure what the entity is supposed to represent.
In any case, you'll need to clarify your data model.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden