我想在我的应用程序中使用可能包含回车符的换行文本字段。有没有什么方法可以强制 NSTextField 对象在文本区域中写入回车符,而不是在按下 Return 键时将其操作发送到目标?
这涵盖在技术问答 QA1454 http://developer.apple.com/library/mac/#qa/qa1454/_index.html,其中还列举了人们会使用的原因NSTextField
代替NSTextView
在这种情况下。
您可以在文本字段委托中实现以下方法:
- (BOOL)control:(NSControl*)control
textView:(NSTextView*)textView
doCommandBySelector:(SEL)commandSelector
{
BOOL result = NO;
if (commandSelector == @selector(insertNewline:))
{
// new line action:
// always insert a line-break character and don’t cause the receiver
// to end editing
[textView insertNewlineIgnoringFieldEditor:self];
result = YES;
}
return result;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)