for those not into reading 20 comments to look for the answer. here is what worked for me:
- the tableView is View Based, not Cell Based (attributes inspector)
- tableView.reloadData() wasn’t fast enough. using insertRow(at[0]:withAnimation:.leftSlide) instead worked fine
- make sure that the NSTextField as well as the NSTextFieldCell are editable (attributes inspector)
the final code:
tableViewAlarms.insertRows(at: [0], withAnimation: .effectFade)
let keyView = tableViewAlarms.view(atColumn: 0, row: 0, makeIfNecessary: false) as! NSTableCellView
self.view.window!.makeFirstResponder(keyView.textField)
the question:
got one question. I have been stuck for some time making my NSTableView work the way I want it to. I'm a beginner and working with classes, inheritance, and views is giving me a lot of trouble.
screenshot, the NSTextField is activated
you add a row to the NSTableView by pushing the '+' button.
the NSTextField in the first tableColumn is editable and begins editing when double-clicked
now I want the NSTextField in the first column to be activated automatically (show cursor, responding to text input via keyboard) when a row is added.
so far i have tried:
class NSTextFieldSubClass: NSTextField {
override func becomeFirstResponder() -> Bool {
return true
}
}
I also played around with the bindings of the cell (or the NSTextField itself to be precise), but since I don't really know my way around those it went nowhere
what I think is the way to go:
make the NSTextField the firstResponder when the cell is created, but I don't know how. Any help is greatly appreciated!!
also: how exactly is the state of an NSTextField called when the cursor is blinking?
edit:
as for the subclass, this is all I tried:
class NSTextFieldSubClass: NSTextField {
override func becomeFirstResponder() -> Bool {
return true
}
}
edit screenshot:
edit2:
edit3:
edit4: