【问题标题】:How to quit the app when the main window is closed关闭主窗口时如何退出应用程序
【发布时间】:2019-08-17 00:31:38
【问题描述】:

我的 macOS 应用程序被拒绝,因为“关闭主窗口不会退出应用程序。”

我已经实现了

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
    return true
}

我的应用委托中的方法,它似乎关闭了应用,所以我不确定它为什么被拒绝。

我可以做些什么来解决这个问题?

【问题讨论】:

  • 显然关闭所有打开的窗口。
  • @user11707424 你看看我的回答吗

标签: swift xcode macos


【解决方案1】:

你必须调用终止 NSApplication:

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
    NSApplication.shared.terminate(self)
    return true
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多