我有一个窗口,它可以使用tab和shift-tab组合键在控件之间愉快地切换。但是,我也希望能够使用向上和向下箭头键(在本例中)在控件之间移动。如何才能做到这一点?
发布于 2010-08-04 07:27:30
对于非文本控件,您应该能够在响应器链中的某个位置(例如,您的NSWindowController)中使用类似的内容:
- (void)keyDown:(NSEvent *)event {
    NSWindow *window = [self window];
    switch ([[event characters] objectAtIndex:0]) {
        case NSUpArrowFunctionKey:
            [window makeFirstResponder:[[window firstResponder] previousValidKeyView]];
            break;
        case NSDownArrowFunctionKey:
            [window makeFirstResponder:[[window firstResponder] nextValidKeyView]];
             break;
       default:
            [super keyDown:event];
            break;
    }
}在文本字段委派中:
- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command {
    NSWindow *window = [control window];
    if (command == @selector(moveUp:)) {
        [window makeFirstResponder:[[window firstResponder] previousValidKeyView]];
        return YES;
    } else if (command == @selector(moveDown:)) {
        [window makeFirstResponder:[[window firstResponder] nextValidKeyView]];
        return YES;
    }
    return NO;        
}(对于文本视图委托,也有类似的方法。)
发布于 2010-08-04 07:27:59
告诉窗口使当前视图的下一个/上一个关键视图成为第一响应者。
https://stackoverflow.com/questions/3399718
复制相似问题