Search code examples
nstableviewnstablecolumn

NSTableCell setDataCell disables editing


I have a NSTableView which I dynamically add columns. I've just added a call to setDataCell to customize my cell. The code looks like:

for(NSUInteger columnIndex = 0; columnIndex < resultSet.columNames.count; ++columnIndex)
{
    NSTableColumn * newColumn = [[NSTableColumn alloc] initWithIdentifier: [NSString stringWithFormat: @"%ld", columnIndex]];

    [newColumn.headerCell setAlignment: NSCenterTextAlignment];
    [newColumn.headerCell setStringValue: resultSet.columNames[columnIndex]];
    [newColumn setDataCell: [[HSDisclosureTextFieldCell alloc] init]];
    [newColumn setEditable: YES];

    [resultsTableView addTableColumn: newColumn];
    if(newColumn.width < 60) [newColumn sizeToFit];
} // End of column loop

If I remove the call to setDataCell then I can still double click my entry and edit it.

I have minimized the HSDisclosureTextFieldCell contains the following (no overrides):

@interface HSDisclosureTextFieldCell : NSTextFieldCell
{
}

But I still cannot double click to edit the field anymore.

Any ideas where I'm going wrong?


Solution

  • Turns out even though I am doing:

    [newColumn setEditable: YES];
    

    and have:

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

    implemented, I needed to switch my setDataCell to be:

    HSDisclosureTextFieldCell * cell = [[HSDisclosureTextFieldCell alloc] init];
    [cell setEditable: YES];
    [newColumn setDataCell: cell];
    

    Now that I have done that, everything seems to be working properly.