如何在使用多个排序描述符列设置指示图像?
-
25-09-2019 - |
题
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]) ? @"NSAscendingSortIndicator" : @"NSDescendingSortIndicator"]
inTableColumn:[tableView tableColumnWithIdentifier:[lastSortDescriptor key]]];
NSLog(@"currentImage: %@", [tableView indicatorImageInTableColumn:[tableView tableColumnWithIdentifier:[lastSortDescriptor key]]]); /* DEBUG LOG */
NSEnableScreenUpdates();
代码上面不设置三角形排序图像。我设置多个排序的描述符,但是它改变到单个一个之后,它开始在列标题,以显示正确的图像。 在这两种情况下,示出了currentImage我,正确的图像被设置(同样为降序):
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>"
的上述方法的行动改变顺序和发送reloadData到我的tableView,对结果没有影响。
有我认为setIndicatorImage正常工作,但不知何故图像不被显示在报头中,或者至少是不可见的。
我缺少什么吗?
修改
代码是用来放NSViewController的子类中的应用程序的窗口的主视图是:
// adding view inside the main view
[mainView addSubview:view];
[view setFrame:[mainView bounds]];
[view display];
[mainView display];
解决方案
OK,我只是发现了一些很简单的解决方法:
[[[tableView tableColumnWithIdentifier:[lastSortDescriptor key]] headerCell]
setStringValue:[columnName stringByAppendingString:([lastSortDescriptor ascending]) ? @" ▲" : @" ▼"]];
不隶属于 StackOverflow