Reputation: 64834
I've changed the sort descriptor for my NSTableView columns. The new descriptor is rockinggood, but now all headers have the sort arrow displayed.
Why? How can I leave the sort arrow for the header belonging to the column I'm currently sorting by ? This is the code (old descriptor is commented out):
//Old descriptor
//NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:metadata.columnSortKeyPath ascending:NO selector:metadata.columnSortSelector];
//New descriptor
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"self" ascending:YES comparator:^NSComparisonResult(id obj1, id obj2) {
if ([obj1 isKindOfClass:[CBFolder class]]) {
return NSOrderedSame;
}
if (currentClickedHeaderTableColumn) {
CBTableColumnMetadata metadata = [(CBApplicationDelegate*)[NSApp delegate] tableColumnMetadataForKey:currentClickedHeaderTableColumn.identifier];
return [[obj1 valueForKey:metadata.columnSortKeyPath] performSelector:metadata.columnSortSelector withObject:[obj2 valueForKey:metadata.columnSortKeyPath]];
}
return NSOrderedSame;
}];
Upvotes: 1
Views: 512
Reputation: 90571
I believe how it works is that the table view has its sortDescriptors
property, which is the array of sort descriptors in effect (primary, secondary, etc.).
A column shows the sort indicator if its sortDescriptorPrototype
matches the first element of the table view's sortDescriptors
.
You appear to be using the same sort descriptor for all of your columns. Therefore, they all match and all show the sort indicator.
I think your sort descriptor is inherently broken because of its reliance on the currentClickedHeaderTableColumn
. That suggests that each column's sort order changes as the "clicked" column changes, which is just broken. A given column's sort order (the order it would be in if the table were sorted by that column) shouldn't change depending on irrelevant state like that.
Upvotes: 2