Overriding the new inter-cell navigation of NSTableView

  • Hi!

    In my app I need to be able to have the return, enter or down arrow key
    give focus to the cell that is under the current one and begin editing,
    to edit sequentially the same attribute of multiple objects.

    What is the best way of doing this?

    Thanks,

    Flofl.
  • > Subject: Overriding the new inter-cell navigation of NSTableView
    >
    > Hi!
    > In my app I need to be able to have the return, enter or down arrow
    > key
    > give focus to the cell that is under the current one and begin
    > editing,
    > to edit sequentially the same attribute of multiple objects.
    > What is the best way of doing this?
    > Thanks,
    > Flofl.

    I found that the keyDown: + interpretKeyEvents method wouldn't work
    with the NSTextFieldCell so I ended up overriding endEditing: (tv is
    an outlet to the parent tableView of the cell):

    - (void)endEditing:(NSText *)textObj {

        int editedRow = [tv editedRow];
        int editedColumn = [tv editedColumn];
        int numberOfRows = [tv numberOfRows];

        editedRow ++;
        editedRow = (editedRow == numberOfRows ? 0 : editedRow); //
    Selects the first row when the las one is reached.

        [super endEditing:textObj];

        // Select the row (needed to avoid an exception to be raised).
        [tv selectRow:editedRow byExtendingSelection:NO];

        [tv editColumn:editedColumn
             row:editedRow
        withEvent:nil
           select:YES];
    }

    It works, but is it the best way? It looks more like a workaround than
    like the regular way of customizing "the tab-loop behavior"... And
    what if I want to take different actions according to the key that
    ended the editing?

    Flofl.
  • >>
    >
    > I found that the keyDown: + interpretKeyEvents method wouldn't work
    > with the NSTextFieldCell so I ended up overriding endEditing: (tv is
    > an outlet to the parent tableView of the cell):
    >
    > - (void)endEditing:(NSText *)textObj {
    >
    > int editedRow = [tv editedRow];
    > int editedColumn = [tv editedColumn];
    > int numberOfRows = [tv numberOfRows];
    >
    > editedRow ++;
    > editedRow = (editedRow == numberOfRows ? 0 : editedRow); //
    > Selects the first row when the las one is reached.
    >
    > [super endEditing:textObj];
    >
    > // Select the row (needed to avoid an exception to be raised).
    > [tv selectRow:editedRow byExtendingSelection:NO];
    >
    > [tv editColumn:editedColumn
    > row:editedRow
    > withEvent:nil
    > select:YES];
    > }
    >
    > It works, but is it the best way? It looks more like a workaround
    > than like the regular way of customizing "the tab-loop behavior"...
    > And what if I want to take different actions according to the key
    > that ended the editing?

    You could override:

    - (void)textDidEndEditing:(NSNotification *)notification {
        NSText *textObject = [notification object];
        NSInteger whyEnd = [[[notification userInfo]
    objectForKey:@"NSTextMovement"] integerValue];

    ...

    corbin
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today