我正在尝试让我的文本字段在用户完成编辑时(比如他们按回车键时)退出first responder。委托方法正在被调用,但我现在拥有的方法不起作用,该如何做才是正确的呢?
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
{
[fieldEditor resignFirstResponder];
return YES;
}发布于 2010-12-14 01:29:30
在关于-resignFirstResponder方法的文档中:
使用NSWindow makeFirstResponder:方法,而不是此方法,使对象成为第一响应者。永远不要直接调用此方法。
这段代码应该能做到这点:
[myWindow makeFirstResponder:nil];发布于 2015-07-28 02:49:03
- (void)controlTextDidEndEditing:(NSNotification *)obj {
[self.window makeFirstResponder:view];
}其中“NSView”是NSTextView控件的父视图。
发布于 2013-08-09 09:11:13
我相信您正在寻找NSControl委托方法:
- (void)controlTextDidEndEditing:(NSNotification *)notif在你的NSTextField委托中实现这个方法(很容易在IB中设置)。
然后您更改响应器的请求,例如
[self.window selectNextKeyView:self]应该行得通。
https://stackoverflow.com/questions/4431068
复制相似问题