我试图用一个tableView实例显示NSViewController的上下文菜单。
...
lazy var contextMenu: NSMenu = {
let rightClickMenu = NSMenu()
rightClickMenu.addItem(withTitle: "Add card", action: #selector(addCard), keyEquivalent: "")
rightClickMenu.addItem(withTitle: "Remove card", action: #selector(removeCard), keyEquivalent: "")
return rightClickMenu
}()
最佳答案
解决方案之一:
...
override func rightMouseDown(with event: NSEvent) {
NSMenu.popUpContextMenu(contextMenu, with: event, for: self.view)
}
...
关于swift - 当我右键单击NSTableView行时如何添加(显示)上下文菜单?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54254114/