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: Bill Hernandez <email@hidden>
- Date: Wed, 17 Mar 2010 14:17:35 -0500
On Mar 17, 2010, at 12:59 PM, 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];
if you are using a loop
> arrangedObjects.numberData
wont work. See if [5302] below helps...
I extract the fieldnames from a tab delimited file, thus the reason for the variable names
for(NSString *tabDelimitedFieldName in theFieldNames)
{
// See NOTE : [5301]
NSTableColumn *aColumn = [[[NSTableColumn alloc] initWithIdentifier:tabDelimitedFieldName] autorelease];
NSString *tabDelimitedFieldNameCapitalized = [[tabDelimitedFieldName stringByReplacingOccurrencesOfString:@"_" withString:@" "] capitalizedString];
[[aColumn headerCell] setStringValue:tabDelimitedFieldNameCapitalized];
[aColumn setWidth:(CGFloat)93.0];
// [5302] This next line is key
NSString *theString = [NSString stringWithFormat:@"arrangedObjects.%@",tabDelimitedFieldName];
[aColumn bind:NSValueBinding toObject:(id)theArrayController withKeyPath:theString options:nil];
[theUserInterfaceTableView addTableColumn:aColumn];
}
> (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.
>
> I've tried many variations of the toObject and withKeyPath: values to no avail. I've looked through all the Key Value Coding and other Apple dev documentation and Googled like mad, but after 3 unproductive days I'm hoping someone here can help.
Bill Hernandez
Plano, Texas
_______________________________________________
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