代码之家  ›  专栏  ›  技术社区  ›  Piotr Byzia

如何在具有多个排序描述符的列上设置指示符图像?

  •  0
  • Piotr Byzia  · 技术社区  · 16 年前
    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>"
    

    在我看来,setIndicatorImage工作正常,但不知何故,图像没有显示在标题中,或者至少是不可见的。

    我错过了什么?

    编辑

    代码用于通过以下方式将NSViewController的子类放置在应用程序窗口的主视图中:

    // adding view inside the main view
    [mainView addSubview:view];
    [view setFrame:[mainView bounds]];
    
    [view display];
    [mainView display];
    
    1 回复  |  直到 16 年前
        1
  •  1
  •   Sangram Shivankar Wostein    8 年前

    好吧,我找到了一些简单的解决方法:

    [[[tableView tableColumnWithIdentifier:[lastSortDescriptor key]] headerCell] 
    setStringValue:[columnName stringByAppendingString:([lastSortDescriptor ascending]) ? @"  ▲" : @"  ▼"]];
    
    推荐文章