简体   繁体   中英

Simulate Tab and Shift-Tab with arrow keys in NSTableView

I want to simulate tab and shift-tab with right arrow and left arrow. I suppossed I have to subclass NSTableview and overide keydown code but I don't know how to tell the table view that has to edit a cell in a column and row. this is how far i get

-(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]];
        }


    }

}

Better than keydown, you can override the NSControl Delegate from the NSTableView:

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

Take a look at the answers from this post: Arrow keys with NSTableView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM