Saturday, September 26, 2009

Cocoa: TableView --- one more thing

Continuing the last post, there is one more thing.

On the question of how to change the Table View programmatically, I finally read the relevant section of the docs, which is titled:

Programmatically Modifying a Controller’s Contents

Make the array controller an outlet, then respond to the add button by modifying it like so:

    NSInteger i;
i = [TVController selectionIndex];
if (i == NSNotFound ) { i = [data count]; }
[TVController insertObject:mD atArrangedObjectIndex:i];
NSLog(@"add %@ %i", [data description], i);

The change will propagate back to the data source automatically. Note that you will have to do a little more fiddling to deal with a multiple selection, or just disable it.

No comments: