Cocoa 从初始状态转换后应用程序不会退出 VC

Cocoa App will not quit after transitioning away from initial VC

这是我的 ViewController 的设置

如果我 运行 应用程序和我从一个视图控制器移动到另一个视图控制器,“退出应用程序名称”菜单项不起作用,视图显示为工作表..

为什么退出功能是唯一一个在离开初始 VC 时未被触发的功能,但其他菜单项(例如最小化)工作正常? 我该如何解决这个问题?

好的,我找到了解决方案。在每个 class 的 ViewVontroller 中,我必须插入:

  override func viewDidAppear() {
      self.view.window!.preventsApplicationTerminationWhenModal = false
    }

Apple 文档:"Usually, application termination is prevented when a modal window or sheet is open, without consulting the application delegate. Some windows may wish not to prevent termination, however. Setting this property to NO overrides the default behavior and allows termination to proceed even if the window is open, either through the sudden termination path if enabled, or after consulting the application delegate."