Search code examples
xcodecocoansviewcontroller

Cocoa App will not quit after transitioning away from initial VC


This is the set up of my ViewControllers VCs

If i run the app and i move from one view controller to the other, the "Quit appName" menu item does not work, views are presented as sheets..

Why is the Quit function the only one not being triggered when moved away from the initial VC, but other menu items(e.g Minimize) work fine? Any how can i fix the issue?


Solution

  • Ok i found the solution. In every class of ViewVontroller that is presented i had to insert:

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

    Apple Doc: "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."