NSTableView Right Clicked Row Index

后端 未结 5 1278
太阳男子
太阳男子 2020-12-29 09:16

I\'m looking for a way to get right-clicked row index from NSTableView but I can\'t find any delegate methods or class attributes for it. Any suggestion is appr

5条回答
  •  有刺的猬
    2020-12-29 09:35

    if you dont need to open NSMenu but need to know "right click action with row number", i think most simple way is below. (Swift4 Code) Don't need any other connected Outer NSMenu class.

    class SomeViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate {
      @IBOutlet weak var tableView: NSTableView!
      ...
    
      override func viewDidLoad() {
        ...
        tableView.action = #selector(some method()) // left single click action
        tableView.doubleAction = #selector(someMethod()) // left double click action
      }
    
      // right click action
      override func rightMouseDown(with theEvent: NSEvent) {
        let point = tableView.convert(theEvent.locationInWindow, from: nil)
        let row = tableView.row(at: point)
        print("right click")
        print(row)
      }
    

提交回复
热议问题