我正在尝试使用一个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
}()
答案 0 :(得分:1)
解决方案之一:
...
override func rightMouseDown(with event: NSEvent) {
NSMenu.popUpContextMenu(contextMenu, with: event, for: self.view)
}
...