1

我有一个基于单元格的 NSTableView,在特定列中有一个文本单元格。我想提供一个自定义字段编辑器,这样我就可以在用户不按 F5 的情况下自动完成。

@implementation AutoCompleteFieldEditorTextView

-(id)init
{
    self = [super init];
    if (self)
    {
        self.focusRingType = NSFocusRingTypeDefault;
        self.fieldEditor = YES;
    }
    return self;
}

@end

除了对焦环不存在外,这可以正常工作。即使我添加:

-(void)drawFocusRingMask
{
    NSRectFill([self bounds]);
}

-(NSRect)focusRingMaskBounds
{
    return [self bounds];
}

它仍然不起作用。如何获得在 NSTableView 中用作字段编辑器的默认 NSTextView 出现的确切焦点环?

4

1 回答 1

1

有同样的问题,为了解决我正在使用下一种方法。此方法在自定义 NSTextFieldCell 中重载,它创建并返回您的自定义 NSTextView:

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
      [super drawInteriorWithFrame:cellFrame inView:controlView];

      if([controlView.window firstResponder] == self.maskTextField)
      {
         [super drawFocusRingMaskWithFrame:cellFrame
                                    inView:controlView];
      }
}

希望这对将来的人有所帮助。

于 2018-12-12T17:04:13.547 回答