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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With