Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well it isn't easy but I managed to do it without having to use RRSpreadSheet or even another control. Here's what you have to do:</p> <ol> <li><p>Create a subclass of <code>NSTextView</code>, this will be the field editor. For this example the name <code>MyFieldEditorClass</code> will be used and <code>myFieldEditor</code> will refer to an instance of this class.</p></li> <li><p>Add a method to <code>MyFieldEditorClass</code> called "<code>- (void) setLastKnownColumn:(unsigned)aCol andRow:(unsigned) aRow</code>" or something similar, and have it save both the input parameter values somewhere.</p></li> <li><p>Add another method called "setTableView:" and have it save the NSTableView object somewhere, or unless there is another way to get the NSTableView object from the field editor, use that.</p></li> <li><p>Add another method called <code>- (void) keyDown:(NSEvent *) event</code>. This is actually overriding the <code>NSResponder</code>'s <code>keyDown:</code>. The source code should be (be aware that StackOverflow's MarkDown is changing <code>&lt;</code> and <code>&gt;</code> to <code>&amp;lt;</code> and <code>&amp;gt;</code>):</p> <pre><code>- (void) keyDown:(NSEvent *) event { unsigned newRow = row, newCol = column; switch ([event keyCode]) { case 126: // Up if (row) newRow = row - 1; break; case 125: // Down if (row &lt; [theTable numberOfRows] - 1) newRow = row + 1; break; case 123: // Left if (column &gt; 1) newCol = column - 1; break; case 124: // Right if (column &lt; [theTable numberOfColumns] - 1) newCol = column + 1; break; default: [super keyDown:event]; return; } [theTable selectRow:newRow byExtendingSelection:NO]; [theTable editColumn:newCol row:newRow withEvent:nil select:YES]; row = newRow; column = newCol; } </code></pre></li> <li><p>Give the NSTableView in your nib a delegate, and in the delegate add the method:</p> <pre><code>- (BOOL) tableView:(NSTableView *)aTableView shouldEditColumn:(NSTableColumn *) aCol row:aRow { if ([aTableView isEqual:TheTableViewYouWantToChangeBehaviour]) [myFieldEditor setLastKnownColumn:[[aTableView tableColumns] indexOfObject:aCol] andRow:aRow]; return YES; } </code></pre></li> <li><p>Finally, give the Table View's main window a delegate and add the method:</p> <pre><code>- (id) windowWillReturnFieldEditor:(NSWindow *) aWindow toObject:(id) anObject { if ([anObject isEqual:TheTableViewYouWantToChangeBehaviour]) { if (!myFieldEditor) { myFieldEditor = [[MyFieldEditorClass alloc] init]; [myFieldEditor setTableView:anObject]; } return myFieldEditor; } else { return nil; } } </code></pre></li> </ol> <p>Run the program and give it a go!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload