失去焦点并单击窗口的关闭按钮?
当 NSTextField 失去焦点时,我有一个方法被触发。此方法在我当前的窗口上显示一个弹出表。
一切都很好,除了当我在文本字段中输入一些内容并连续通过单击关闭按钮关闭窗口时。在这种情况下:
- 文本字段失去焦点,该方法被触发,它显示弹出窗口,
但
- 窗口无论如何都被关闭,因为我单击了“关闭”按钮,因此弹出窗口仅可见几秒钟。
谢谢
I've a method triggered when a NSTextField looses focus. This method displays a popup sheet over my current window.
Everything works great except when I've typed something in the text field and successively I close the window by clicking on the close button. In this case:
- the text field loses focus and the method is triggered and it shows the popup
but
- the window is dismissed anyway, because I've clicked the Close button, so the popup is visible only for few seconds.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该创建一个
NSWindowDelegate
并实现-windowShouldClose:
如果弹出窗口可见或者文本字段是前一个第一响应者(或者您确定文本字段失去焦点),则返回NO
。You should create an
NSWindowDelegate
and implement-windowShouldClose:
to returnNO
if the popup is visible or if the text field was the previous first responder (or however else you're determining that the text field lost focus).