NSDisableScreenUpdates();
[self.productsArrayController setFetchPredicate:predicate];
[self.productsArrayController setSortDescriptors:sortDescriptors];
[self.productsArrayController fetchWithRequest:[self.productsArrayController defaultFetchRequest] merge:YES error:nil];
NSSortDescriptor *lastSortDescriptor = [sortDescriptors lastObject];
[tableView setHighlightedTableColumn:[tableView tableColumnWithIdentifier:[lastSortDescriptor key]]];
[tableView setIndicatorImage:[NSImage imageNamed: ([lastSortDescriptor ascending]) ? @"NSAscendingSortIn开发者_StackOverflow中文版dicator" : @"NSDescendingSortIndicator"]
inTableColumn:[tableView tableColumnWithIdentifier:[lastSortDescriptor key]]];
NSLog(@"currentImage: %@", [tableView indicatorImageInTableColumn:[tableView tableColumnWithIdentifier:[lastSortDescriptor key]]]); /* DEBUG LOG */
NSEnableScreenUpdates();
Code above doesn't set a triangle sorting image. I'm setting multiple sorting descriptors, but after changing it to a single one, it starts to display correct image in column header. In both cases, currentImage shows me that correct image is set (the same for descending order):
currentImage: <NSImage 0x200495fc0 Name=NSAscendingSortIndicator Size={9, 9} Reps=(
"NSBitmapImageRep 0x20049f480 Size={9, 9} ColorSpace=Generic RGB colorspace BPS=8 BPP=32 Pixels=9x9 Alpha=YES Planar=NO Format=0 CurrentBacking=<CGImageRef: 0x2004a9e80>"
Changing order of actions in above method and sending reloadData to my tableView, had no effect on results.
It seems to me that setIndicatorImage works as expected, but somehow image is not being displayed in the header, or at least is not visible.
What am I missing here?
EDIT
Code is used to put a subclass of NSViewController in the main view of app's window by:
// adding view inside the main view
[mainView addSubview:view];
[view setFrame:[mainView bounds]];
[view display];
[mainView display];
OK, I've just found some simple enough work-around:
[[[tableView tableColumnWithIdentifier:[lastSortDescriptor key]] headerCell]
setStringValue:[columnName stringByAppendingString:([lastSortDescriptor ascending]) ? @" ▲" : @" ▼"]];
精彩评论