swift – 试图了解基于macOS Document的应用程序窗口何时关闭

swift – 试图了解基于macOS Document的应用程序窗口何时关闭,第1张

概述我试图知道窗口何时关闭,我实现了这段代码: class ViewController: NSViewController, NSWindowDelegate { override func viewDidLoad() { super.viewDidLoad() let window: NSWindow? = view.window win 我试图知道窗口何时关闭,我实现了这段代码:
class 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

问题是window属性将始终在vIEwDIDLoadMethod中返回nil.您需要在vIEwWillAppear方法中设置委托:
class VIEwController: NSVIEwController,NSWindowDelegate {    overrIDe func vIEwWillAppear() {        super.vIEwWillAppear()        vIEw.window?.delegate = self    }    func windowWillClose(_ aNotification: Notification) {        print("windowWillClose")    }}
总结

以上是内存溢出为你收集整理的swift – 试图了解基于macOS Document的应用程序窗口何时关闭全部内容,希望文章能够帮你解决swift – 试图了解基于macOS Document的应用程序窗口何时关闭所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1036941.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存