2

我想用右箭头和左箭头模拟选项卡和移位选项卡。我想我必须继承 NSTableview 并覆盖 keydown 代码,但我不知道如何告诉表格视图必须编辑列和行中的单元格。这就是我能走多远

-(void)keyDown:(NSEvent*)event{
    [super keyDown:event];
    NSLog(@"%hi", [event keyCode]);

        if ([event keyCode] == 48 && ([event modifierFlags] &
                                  NSShiftKeyMask)){
        [[self window] selectKeyViewPrecedingView:self];
    }

    if ([event keyCode] == 51){
        [[self window] selectKeyViewPrecedingView:self];

    }
    if ([event keyCode] == 124){
        if ([self selectedColumn] < [self numberOfColumns]-1) {

            [self performClickOnCellAtColumn:[self selectedColumn]+1 row:[self selectedRow]];
        }


    }
    if ([event keyCode] == 124){
        if ([self selectedColumn] > 0) {
            [self performClickOnCellAtColumn:[self selectedColumn]-1 row:[self selectedRow]];
        }


    }

}
4

2 回答 2

0

-[NSTableView editColumn:row:withEvent:select:]

于 2011-06-24T16:36:21.823 回答
0

比 keydown 更好,您可以从 NSTableView 覆盖 NSControl 委托:

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

看看这篇文章的答案:Arrow keys with NSTableView

于 2012-02-03T13:32:21.237 回答