NSTableView hit tab to jump from row to row while editing

后端 未结 2 512
难免孤独
难免孤独 2021-02-10 06:27

I\'ve got an NSTableView. While editing, if I hit tab it automatically jumps me to the next column. This is fantastic, but when I\'m editing the field in the last column and I h

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-10 07:25

    Subclass UITableView and add code to catch the textDidEndEditing call.

    You can then decide what to do based on something like this:

    - (void) textDidEndEditing: (NSNotification *) notification
    {
        NSDictionary *userInfo = [notification userInfo];
    
        int textMovement = [[userInfo valueForKey:@"NSTextMovement"] intValue];
    
        if ([self selectedColumn] == ([[self tableColumns] count] - 1))
            (textMovement == NSTabTextMovement)
        {
            // the tab key was hit while in the last column, 
            // so go to the left most cell in the next row
            [yourTableView editColumn: 0 row: ([self selectedRow] + 1)  withEvent: nil select: YES];
        }
    
        [super textDidEndEditing: notification];
        [[self window] makeFirstResponder:self];
    
    } // textDidEndEditing
    

    This code isn't tested... no warranties... etc. And you might need to move that [super textDidEndEditing:] call for the tab-in-the-right-most-cell case. But hopefully this will help you to the finish line. Let me know!

提交回复
热议问题