mica mica - 1 month ago 10
Swift Question

focus a field in a NSTableCellView for instant editing

I want to set the focus on one of two editfields in a NSTableCellView in a table with one column in a row programaticly, so that a user can instantly edit the field.
In my example I can select the row (after pressing a button), but I cannĀ“t find a way to set the focus on a special field.

I my example I want to set the cursor on the tiltle field in row 3.

class MainVC: NSViewController, NSTableViewDataSource, NSTableViewDelegate
{ var t = [Item]()
@IBOutlet weak var itemTV: NSTableView!
@IBAction func actionBu(_ sender: Any)
let indexSet = IndexSet(integer: 2)
itemTV.selectRowIndexes(indexSet, byExtendingSelection: false)

enter image description here

enter image description here

Answer Source

thanks to all helping commands, I found an solution

@IBAction func actionBu(_ sender: Any)
  { self.view.window!.makeFirstResponder(itemTV.view(atColumn: 0, row: 2, makeIfNecessary: true)?.subviews[0])

works fine for me,