获取功能键按下NSSearchField而不进行子类化

Jav*_*rán 3 cocoa objective-c nsevent nssearchfield

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

编辑

keyUp:我在NSSearchField子类中重写的方法是:

-(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
    }
}
Run Code Online (Sandbox Code Playgroud)

Fra*_*rew 11

将控制器指定为搜索字段的代理并实现该方法:

- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command
Run Code Online (Sandbox Code Playgroud)

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