Search code examples
macosswiftcocoanstableviewnstextfield

NSTableView textfield cell should not go into edit on click


I have two NSTableViews in my app and both are set up the same, same parameters, etc., they have several columns with NSTextField cells and the first column is editable.

The first table behaves like I want it: if the user clicks, the row is selected. If the user clicks the row a second time the textfield goes into edit mode, letting the user change the text in it.

The second table should act the same but it doesn't: if I click a row in it, most of the time it goes straight into edit mode with the textfield. Very, very rarely this does not happen.

Does anyone know what causes this? I checked all parameters (in IB) and code and they are the same on both tables. If I set 'Refuses first responder' on the textfield in the naughty table, it doesn't let me edit the textfield at all so that option doesn't help.


Solution

  • SOLVED IT! The reason why it works on the first table view but caused the edit issue on the second table was because the first table allows dragging while the second did not! It seems somehow this interferes with doubleAction (I even read somewhere that an editable table cannot have doubleAction but it seems to work without problems). I could fix it by implementing tableView(_:writeRowsWithIndexes:toPasteboard:) in the second tableview's view controller and simply return false (since the 2. table should not have drag'n'drop ability) ...

    func tableView(aTableView:NSTableView, writeRowsWithIndexes rowIndexes:NSIndexSet, toPasteboard pboard:NSPasteboard) -> Bool
    {
        return false;
    }