Sco*_*col 5 macos xcode objective-c
我希望我的 NSTextField 在输入时添加另一行(而不是选项输入)。有没有办法做到这一点?
干杯!
是的 - 通过覆盖control范围NSTextFieldDelegate,您可以拦截 Enter 按键并使其执行您想要的操作。
下面是改编自文章“如何使 NSTextField 接受 Tab、Return 和 Enter 键”的示例。在 Apple 的开发者门户上:
(BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector
{
if (commandSelector == @selector(insertNewline:))
{
// Insert a line-break character and don't cause the receiver
// to end editing
[textView insertNewlineIgnoringFieldEditor:self];
return YES;
}
return NO;
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,这NSTextView*并不是一个拼写错误,尽管我们正在处理NSTextFields。
| 归档时间: |
|
| 查看次数: |
2012 次 |
| 最近记录: |