2012-12-01 33 views

回答

2

您需要继承NSTableview并覆盖-highlightSelectionInClipRect:方法。

它可以这样做:

从定期更改您的tableView的高亮模式源列表属性检查器

Change highlight mode image

现在继承NSTableView这样的:

-(void)highlightSelectionInClipRect:(NSRect)theClipRect 
{ 
    NSRange visibleRowIndexes = [self rowsInRect:theClipRect]; 
    NSIndexSet *selectedRowIndexes = [self selectedRowIndexes]; 
    NSUInteger endRow = visibleRowIndexes.location + visibleRowIndexes.length; 
    NSUInteger row; 

    for (row=visibleRowIndexes.location; row<endRow; row++) 
    { 
     if([selectedRowIndexes containsIndex:row]) 
     { 
      NSRect rowRect = NSInsetRect([self rectOfRow:row], 3, 4); 
      NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:rowRect xRadius:4.0 yRadius:4.0]; 
      [[NSColor colorWithCalibratedRed:0.474 green:0.588 blue:0.743 alpha:1] set]; 
      [path fill]; 
     } 
    } 
} 

结果:

Result image

+0

谢谢您的回答。但它不适用于我的tableview视图。我已经用基于单元格的方式对它进行了测试,它工作正常。如何在基于视图的tableview上做到这一点? –

+0

@PedroVieira查看基于tableView看看苹果的例子** HoverTableDemo **(这个例子应该回答你的问题):https://developer.apple.com/library/mac/#samplecode/HoverTableDemo/Introduction/Intro。 html#// apple_ref/doc/uid/DTS40011082 –

+1

10.10这个方法不会被调用,如果你使用源列表 – rozochkin