gpt4 book ai didi

objective-c - 在没有子类化的情况下获取 NSSearchField 上的功能键

转载 作者:搜寻专家 更新时间:2023-10-30 19:51:49 25 4
gpt4 key购买 nike

我有一个简单的应用程序,它有一个 NSSearchField,我想知道用户是否按下了一个箭头键。我不想子类化,因为我想在我的应用程序中修改 IBOutlets 的值,但我不能在子类中这样做。

编辑

我在 NSSearchField 子类中覆盖的 keyUp: 方法是:

-(void)keyUp:(NSEvent*)event
{
if ([event keyCode]==36){
customers* c= [[customers alloc] init];//customers is the class where i have my IBOulets and my methods
[[self window] selectKeyViewFollowingView:self];// change the first responder
[c searcht:[self stringValue]];//here i want to call a method to make a query and change the stringValues of some IBOulets
}
}

最佳答案

将您的 Controller 指定为搜索字段的委托(delegate)并实现该方法:

- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command

然后您应该能够接收简单的 NSResponder 选择器,例如 moveDown:、moveUp:、moveLeft:、moveRight:,它们对应于箭头键。

关于objective-c - 在没有子类化的情况下获取 NSSearchField 上的功能键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5833367/

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