Hi all,

I'm fairly comfortable with setting up bindings for table columns to an NSArrayController. Now I'd like to use bindings where the columns change at runtime. Is this possible? I am avoiding using CoreData (so I can run on Mac OS X 10.3 ish and upwards).

Picking up on my own post:

I managed to create table columns at runtime and bind them to my array controller, using:

[newTableColumn bind:@"value" toObject:dataRowsController withKeyPath: [NSString stringWithFormat: @"arrangedObjects.%@", columnName] options:nil];

I've appended the full code below. It took me a while to realise that in the bind:toObject:withKeyPath:options: method, the withKeyPath: parameter concatenates two fields that appear in Interface Builder's GUI: "Controller Key" and "Model Key Path".

// Code to add new columns and bind them to the array controller
// Remove old columns:
NSMutableArray* oldTableColumns = [NSArray arrayWithArray: [dataRowsTableView tableColumns]];
for (NSTableColumn* oldTableColumn in oldTableColumns)
        [dataRowsTableView removeTableColumn:oldTableColumn];
        
// Add new columns:
NSArray* columnNameArray = [[dataRowsArray objectAtIndex:0] allKeys];
for (NSString* columnName in columnNameArray)
{
NSTableColumn* newTableColumn = [[[NSTableColumn alloc] initWithIdentifier:columnName] autorelease];
        [[newTableColumn headerCell] setStringValue:columnName];
        [dataRowsTableView addTableColumn:newTableColumn];
[newTableColumn bind:@"value" toObject:dataRowsController withKeyPath: [NSString stringWithFormat: @"arrangedObjects.%@", columnName] options:nil];
}

Now I've also bound my dataRowsController to the selection of another controller (an NSTreeController). I have a dataRowsArray accessor method setup, so the correct array loads. If the table columns are already in place (such as by me manually running the code above), the data displays perfectly. But I can't see how to trigger my code above (that creates and binds table columns) when the selection changes.

Any ideas?

Thanks,
Tom
BareFeet

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to