如何在 NSMenuItem 的 Action 中打开窗口
可以使用以下代码在 action 中打开窗口:
let windowController = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "windowController") as! NSWindowController
windowController.showWindow(nil)
这里使用了 NSStoryboard 来获取窗口控制器对象,并调用 showWindow 方法来显示窗口。需要注意的是,需要在 Main.storyboard 中给窗口控制器设置一个唯一的标识符,这里使用了字符串 'windowController' 作为标识符。
原文地址: https://www.cveoy.top/t/topic/otQf 著作权归作者所有。请勿转载和采集!