Search code examples
swiftmacoscocoansoutlineview

select outlineView row with nsbutton


i working with swift 4 for osx. i have nsoutlineview with custom cells. in each cell is a button.

in my outlineView-Controller-Class is an IBAction action for this button:

@IBAction func showInfo(_ sender: NSButton) {     

   // Get the row of clicked button
   print(myOutlineView.row(for: sender as NSView))

}

but i also would like to select the row of this button. i guess i have to use this command:

myOutlineView.selectRowIndexes(<NSIndexSet>, byExtendingSelection: <Bool>)

but how can i get the NSIndexSet value?


Solution

  • okay, i found the solution:

    myOutlineView.selectRowIndexes(IndexSet(integer: myOutlineView.row(for: sender as NSView)), byExtendingSelection: false)