Get button's row in view based table

后端 未结 5 1661
情深已故
情深已故 2020-12-17 20:34

How do you get the row for a button in a view based table when you click the button? The row is not selected when the button is clicked, but I found that if you log sender.s

5条回答
  •  旧时难觅i
    2020-12-17 20:42

    I share this code for Swift 4.

    func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
       ........
       but.action =  #selector(ViewController.buttonAction)
       .........
    }
    
    @objc func buttonAction(but: NSButton){
       let tablerow: NSTableRowView = but.superview?.superview as! NSTableRowView;
       let index = table?.row(for: tablerow);
       print("\(index));
    }
    

提交回复
热议问题