gpt4 book ai didi

cocoa - 当使用 NSTextFieldDelegate 时 - 控制 :textView:doCommandBySelector: how do we allow/make normal performance of e. g。退格键?

转载 作者:行者123 更新时间:2023-12-03 16:57:10 29 4
gpt4 key购买 nike

在另一个 SO 线程( Execute an Action when the Enter-Key is pressed in a NSTextField? )中,我看到了这个建议的代码,用于在 NSTextField 中按 Enter 键时执行操作:

- (void)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector
{
NSLog(@"Selector method is (%@)", NSStringFromSelector( commandSelector ) );
if (commandSelector == @selector(insertNewline:)) {
//Do something against ENTER key

} else if (commandSelector == @selector(deleteForward:)) {
//Do something against DELETE key

} else if (commandSelector == @selector(deleteBackward:)) {
//Do something against BACKSPACE key

} else if (commandSelector == @selector(insertTab:)) {
//Do something against TAB key
}
}

但是当我使用它时,退格键和制表符不再正常工作。如何解决这个问题?

我尝试对原始帖子发表评论,但没有足够的声誉来发表评论...TIA

最佳答案

control:doCommandBySelector: 应返回 bool。如果您已处理该事件并且不希望系统执行更多操作,则返回 true;如果您仍希望系统执行该事件的默认实现,则返回 false给定选择器。因此,当选择器是退格键或制表符选择器时,您需要返回false

关于cocoa - 当使用 NSTextFieldDelegate 时 - 控制 :textView:doCommandBySelector: how do we allow/make normal performance of e. g。退格键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29005859/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com