NSTableView sets sort column?

I have an NSTableView with multiple columns. the click of each column is sorted by column, as in iTunes. However, when the tables are first loaded, the rows are not sorted, and no table is highlighted or displays the image displayed up / down. I am wondering if theres an easy way, I can programmatically set a column that is sorted in a table, and set the indicator image at startup.

The only solution I can think of is to use [NSTableView setIndicatorImage: inTableColumn:] and [NSTableView setHighlightedColumn:], but this ensures that clicking on the header does not highlight the column. I would prefer not to use tableView: mouseDownInHeaderOfTableColumn: and rewrite all the click on the header for sorting.

+4
source share
1 answer

You can try setting your sort descriptor.

- (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

+8
source

Source: https://habr.com/ru/post/1306979/


All Articles