views:

165

answers:

1

I have a NSTableView with multiple columns. clicking each of the columns sorts by the column like in iTunes. However when the tableview first loads the rows are unsorted and no tablecolumn is highlighted or displaying the up/down indicator image. I'm wondering if theres a simple way I can programmatically set the column the table is sorted by and set the indicator image on startup.

The only solution I can think of is using [NSTableView setIndicatorImage: inTableColumn:] and [NSTableView setHighlightedColumn:], but that makes it so that clicking on the header doesnt highlight the column. I would rather not have to use tableView:mouseDownInHeaderOfTableColumn: and rewrite the whole click on header to sort thing.

+2  A: 

You might try setting your sort discriptor.

- (void)setSortDescriptors:(NSArray *)array


- (void)windowControllerDidLoadNib:(NSWindowController *) windowController
{
   [super windowControllerDidLoadNib:windowController];
   NSSortDescriptor* sortDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"order" ascending: YES] autorelease];
   [oTable setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
}

http://lists.apple.com/archives/cocoa-dev/2006/May/msg01434.html

Shadow
Wow! that worked! thanks.
overcyn
Awesome, glad it worked!!
Shadow