I want to popup a NSMenu
when the user right-clicks on a NSTableCellView
within a NSTableView
.
let cell = myTableView.make(withIdentifier: "myCustomTableCellView", owner: self) as! MyTableCellView // subclass of NSTableCellView
let menu = NSMenu()
menu.autoenablesItems = false
menu.addItem(NSMenuItem(title: "Test", action: nil, keyEquivalent: ""))
cell.menu = menu
But the menu pops not up if the user clicks on the cell.
I couldn’t find any sendActionOn
methods or something similar.
Would be great if someone could help!
No need to do anything fancy. You can design your menu in Interface Builder.
Menu
from the Object Library to your View ControllerTable View
to this menu and connect it to the menu
outletIBActions
in your View Controller
:Say you have 3 actions on your right-click menu
@IBAction func menuAction1(_ sender: Any) {
print("You clicked Item 1 for row \(self.tableView.selectedRow)")
}
@IBAction func menuAction2(_ sender: Any) {
print("You clicked Item 2 for row \(self.tableView.selectedRow)")
}
@IBAction func menuAction3(_ sender: Any) {
print("You clicked Item 3 for row \(self.tableView.selectedRow)")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With