1

I have an NSOutlineView. When I edit a cell in it and hit return, I would like the cell directly below it to go immediately into edit mode.

I thought I would use the controlTextDidEndEditing: delegate method to find out when editing of a cell had finished, and the editColumn:row:withEvent:select: method to put the cell below it into edit mode.

Here's a demo method that I pasted into "appcontroller.m" of the Apple demo code project, "DragNDropOutlineView":

- (void)controlTextDidEndEditing:(NSNotification *)aNotification
{
    NSTreeNode* treeNodeJustEdited;
    NSInteger indexOfCurrentRow = [outlineView selectedRow];
    if (indexOfCurrentRow < 0) //no row selected
        return;

    treeNodeJustEdited = [outlineView itemAtRow:indexOfCurrentRow];
    NSTreeNode* theRootNode = rootTreeNode;
    NSInteger numberOfChildren = [[theRootNode mutableChildNodes]count];
    NSInteger indexOfLastChild = numberOfChildren - 1;

    if (indexOfCurrentRow < indexOfLastChild)
    {
       [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:indexOfCurrentRow+1] byExtendingSelection:NO];
       [outlineView editColumn:0 row: indexOfCurrentRow+1 withEvent:nil select:NO];
    }
}

For some reason, this does the following:

  • Correctly highlights the row below the cell just edited. But then:
  • Disables that highlighting, i.e. puts it in light grey
  • Makes the cell below the cell just edited, invisible. Clicking twice on that cell returns the table to normal.

What am I missing in order to get this method to perform as desired?

Justin Boo
  • 10,132
  • 8
  • 50
  • 71
VikR
  • 4,818
  • 8
  • 51
  • 96

1 Answers1

0

Here is another question, it is similar with yours

Hope helpfully.

NSTableView & NSOutlineView editing on tab key

Community
  • 1
  • 1
larntin
  • 110
  • 1
  • 10