Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSTableView setting the sort column?

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.

like image 655
overcyn Avatar asked Feb 27 '23 04:02

overcyn


1 Answers

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

like image 157
Kaili Avatar answered Mar 13 '23 03:03

Kaili