【问题标题】:Configuring the Field Editor for an NSPopover为 NSPopover 配置字段编辑器
【发布时间】:2012-06-30 06:35:07
【问题描述】:

这里是 Cocoa 新手:我似乎首先要接触所有真正神秘的东西。我想要一个 NSTextField,点击时默认选择其中的内容,并且我可以在其中更改选择颜色。我在这个论坛上找到了足够多的东西让我开始了解现场编辑的奥秘。我有 NSTextField 的子类,并覆盖了 becomeFirstResponder 方法:

- (BOOL) becomeFirstResponder {
    if (!super.becomeFirstResponder) return NO;
    NSTextView * fieldEditor = (NSTextView *) [self.window fieldEditor:YES forObject:self];
    [fieldEditor performSelector:@selector(selectAll:) withObject:fieldEditor afterDelay:0];
    [fieldEditor setSelectedTextAttributes:selectionColor];
    return YES; }

其中 selectionColor 是一个单项 NSDictionary,其 NSColor 对象键入 NSBackgroundColorAttributeName。这对于窗口和面板上的文本字段非常有效,但对于 NSPopover 视图中的字段根本不起作用。事实上,它使文本选择变得不可能。仍然可以在字段中单击并键入,但在文本中拖动光标以选择它会失败。我只能得出结论,我以某种方式错误地配置了字段编辑器。我是否正确引用它?

【问题讨论】:

    标签: osx-lion fieldeditor nspopover


    【解决方案1】:

    我希望我在回答我自己的问题时遵循 stackOverflow 协议。简短的回答是,显然,我发布的代码非常适合 NSPopovers。我认为它不起作用的可能原因是我称为 selectionColor 的 NSDictionary 对象没有被正确初始化。我在这里有一个 Emily Litella 时刻:“哦……没关系!”在我看来,现在唯一的问题是我花了很长时间才找到这个。

    【讨论】:

      猜你喜欢
      • 2011-11-05
      • 2015-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-30
      • 2012-09-23
      • 1970-01-01
      相关资源
      最近更新 更多