无法在运行时在工作表中编辑NSTextField [英] can't edit NSTextField in sheet at runtime

查看:172
本文介绍了无法在运行时在工作表中编辑NSTextField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击按钮时,我想显示带有电子邮件+密码提示的工作表,并提供保存和取消选项。 UI已完成设置,操作已就位,工作表将按预期显示和取消。问题是我不能在运行时编辑任何NSTextFields;它们似乎禁用,并且在打开工作表时每次按下键时都会播放操作系统错误声音。我阅读了, UIActionSheet 是适当的,但这个不是iOS应用程式。

When clicking on a button, I'd like to display a sheet with an email+password prompt with options to save and cancel. The UI is all set up, the actions are in place, and the sheet appears and cancels as expected. The problem is that I can't edit either of the NSTextFields at runtime; they appear to disabled, and the OS error sound plays on every key press when the sheet is open. I read on SO that UIActionSheet is appropriate, but this is not an iOS app.

文字栏位已启用,之前已在其他面板中使用。我确保IBAction链接是完整的,但我不知道如何解决。

The textfields are enabled, and had previously been working in another panel. I made sure that the IBAction links are intact, but I'm otherwise not even sure how to troubleshoot.

如果一个工作表会导致一个健康的NSTextField拒绝输入

What about a sheet would cause an otherwise healthy NSTextField to refuse input?

// show the sheet
-(IBAction)showAccount:(id)sender {
    [NSApp beginSheet:accountWindow 
       modalForWindow:prefsWindow
        modalDelegate:self 
       didEndSelector:NULL 
          contextInfo:NULL];
}

// cancel/hide the sheet
-(IBAction)cancelAccount:(id)sender {
    [NSApp endSheet:accountWindow];
    [accountWindow orderOut:nil];   
}

编辑:我刚刚发现我可以右键单击并粘贴文本进入每个字段,但我不能选择或删除。看起来像NSTextFields没有得到重点,不接收键盘输入像他们通常会。我也忘了提到我的保存按钮调用并正确执行它的相关方法。

I've just discovered that I can right-click and paste text into each field, but I can't select or delete. It seems like the NSTextFields aren't getting focus and don't receive keyboard input like they usually would. I also forgot to mention that my Save button calls and executes its related method properly.

推荐答案

视图不一定标题栏。

查看
为什么NSWindow没有styleMask:NSTitledWindowMask不能是keyWindow?

这说明:如果你想要一个无标题窗口要成为一个关键窗口,您需要创建一个NSWindow的子类并重写-canBecomeKeyWindow如下:

Which states: If you want a titleless window to be able to become a key window, you need to create a subclass of NSWindow and override -canBecomeKeyWindow as follows:

- (BOOL)canBecomeKeyWindow {
    return YES;
}

这对我有用。

这篇关于无法在运行时在工作表中编辑NSTextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆