【问题标题】:how to make NSTextField editable如何使 NSTextField 可编辑
【发布时间】:2011-07-14 07:38:58
【问题描述】:

我正在创建一个从 NSPanel 继承的自定义类,这个面板是我的应用程序的登陆屏幕。

我在它上面添加了一个 NSTextField,它在屏幕上可见。问题是文本字段不可编辑。

但是,如果我创建一个新的 cocoa 项目并为文本字段运行相同的 addSubview 代码,一切都很好,我可以编辑文本字段。

在我看来,问题出在我的自定义面板上,但我无法找到它。

这是我的代码:

NSTextField *infoTextField = [[NSTextField alloc] initWithFrame:rect];
[[window contentView] addSubview:infoTextField];
[infoTextField setDelegate:self];
[[infoTextField window] becomeFirstResponder];
[infoTextField setTextColor:[NSColor blackColor]];
[infoTextField setDrawsBackground:YES];
[infoTextField setBordered:YES];
[infoTextField setSelectable:YES];
[infoTextField setEditable:YES];
[infoTextField setEnabled:YES];
[infoTextField setAlignment:NSLeftTextAlignment];
[infoTextField setStringValue:@"What are you doing?"];
[infoTextField release];

我需要你的帮助...

【问题讨论】:

    标签: cocoa nstextfield


    【解决方案1】:

    重写 NSPanel 子类中的方法,

    - (BOOL)canBecomeKeyWindow {
        return YES;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 2011-11-05
      • 2020-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多