无法在运行时编辑工作表中的 NSTextField
单击按钮时,我想显示一个带有电子邮件+密码提示的工作表,其中包含保存和取消的选项。 UI 已全部设置完毕,操作已就位,并且工作表按预期显示和取消。问题是我无法在运行时编辑任何一个 NSTextFields;它们似乎被禁用,并且当工作表打开时,每次按键都会播放操作系统错误声音。我读到 UIActionSheet 是合适的,但这不是一个 iOS 应用程序。
文本字段已启用,并且之前已在另一个面板中工作。我确保 IBAction 链接完好无损,但我什至不知道如何排除故障。
如果工作表会导致原本健康的 NSTextField 拒绝输入呢?
// 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 没有获得焦点,也没有像平常一样接收键盘输入。我还忘记提及我的“保存”按钮正确调用并执行其相关方法。
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.
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.
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];
}
Edit: 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,我偶然找到了解决方案,我现在将其发布给后代...
用作工作表(NSWindow 或 NSPanel)的视图需要有一个标题栏。我在 Interface Builder 的检查器(窗口 → 外观 → 标题栏复选框)中切换了此选项,然后重新编译,并像在任何其他视图中一样突出显示、选项卡式显示 NSTextFields 并接受输入。不知道为什么标题栏会有所不同,但你已经明白了。
It turns out that I haphazardly found the solution, which I will now post for posterity...
The view that gets used as the sheet (NSWindow or NSPanel) needs to have a title bar. As soon as I toggled this in Interface Builder's inspector (Window → Appearance → Title Bar checkbox), I recompiled and the NSTextFields highlighted, tabbed, and accepted input like they would in any other view. Not sure why the title bar makes a difference, but there you have it.
视图不一定必须有标题栏。
看
为什么没有 styleMask 的 NSWindow:NSTitledWindowMask 不能是 keyWindow?
状态:如果您希望无标题窗口能够成为关键窗口,您需要创建 NSWindow 的子类并重写 -canBecomeKeyWindow ,如下所示
:为我工作。
The view does not absolutely have to have a title bar.
See
Why NSWindow without styleMask:NSTitledWindowMask can not be keyWindow?
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:
This worked for me.