我试图知道窗口何时关闭,我实现了这段代码:
原文链接:/swift/319538.htmlclass ViewController: NSViewController,NSWindowDelegate { override func viewDidLoad() { super.viewDidLoad() let window: NSWindow? = view.window window?.delegate = self } func windowWillClose(_ aNotification: Notification) { print("windowWillClose") } }
不幸的是没有任何事情发生,我能犯错什么?
文件:https://developer.apple.com/documentation/appkit/nswindow/1419400-willclosenotification
PS
我已经在没有找到解决方案的情况下阅读了这个问题:Handle close event of the window in Swift