0

If I use the following code to start editing a NSTableView:

    [dataTableView editColumn: 0
                          row: 0
                    withEvent: nil
                       select: YES];

The very first row/column combination in the table is now in edit mode. However if I have more than one column and I hit the tab button, the editor does not switch to the next column. Rather, editing mode exists.

If I were to click on the first row/column to enter edit mode, when I hit tab, the field editor moves to the next column (as I would expect).

Any ideas why this would happen? And how I could get my call to editColumn:row:withEvent:select: to tab properly?

Kyle
  • 17,317
  • 32
  • 140
  • 246
  • 1
    This link can help you to solve your problem http://stackoverflow.com/questions/7536167/nstableview-hit-tab-to-jump-from-row-to-row-while-editing – PR Singh Sep 27 '13 at 10:26

2 Answers2

2

The built-in tabbing behavior depends on the row being selected, so just select the row along with editing the column:

[self.tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:rowIndex] byExtendingSelection:NO];
[self.tableView editColumn:0 row:rowIndex withEvent:nil select:YES];
robenkleene
  • 572
  • 8
  • 17
1

As someone said in this answer, the AppKit Release Notes say that tabbing between cells should work automatically. Your tableview delegate probably isn't implementing this method:

- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row

If you want to customize the tab behavior, you need to make your controller be the delegate of your text views and then implement:

- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector {
    if (aSelector == @selector(insertTab:)) {
        ..
    } else if (aSelector == @selector(insertBacktab:)) {
        ..
    }
}
Community
  • 1
  • 1
Pierre Houston
  • 1,631
  • 20
  • 33