NSTextField正在辞职第一响应者 [英] NSTextField resigning first responder
本文介绍了NSTextField正在辞职第一响应者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想让我的文字字段在使用者完成编辑时(例如按下Enter键时)将第一个回应者辞职。代理方法正在调用,但我现在不工作,正确的方法是这样做?
I'm trying to have my text field resign first responder when the user is done editing it, like when they hit enter. The delegate method is getting called but what I have now doesn't work, what is the proper way to go about doing this?
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
{
[fieldEditor resignFirstResponder];
return YES;
}
推荐答案
resignFirstResponder方法:
From the docs on the -resignFirstResponder method:
使用NSWindow makeFirstResponder:
方法,而不是此方法,使
对象成为第一个响应者。从不
直接调用此方法。
Use the NSWindow makeFirstResponder: method, not this method, to make an object the first responder. Never invoke this method directly.
此代码应该:
[myWindow makeFirstResponder:nil];
这篇关于NSTextField正在辞职第一响应者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文