1
votes

I'm trying to get an NSWindow to appear when the respective button for that window is clicked (about -> aboutWindow, preferences -> preferencesWindow). When I click the button to open the window(s), though, they flash and then disappear. I saw a post or two about this describing how to fix it, but it was relatively vague, as well as explained in Objective-C, not Swift. I think I know what the problem is (instance created inside the @IBAction, getting rid of the instance once the action has finished), but I'm not sure how to fix it.

All code is over at https://github.com/madebybright/Nimble/tree/windows

An explanation for the fix would be much appreciated.

1

1 Answers

1
votes

You just need to move the declaration of your controller out of your method. Try like this:

let aboutController = AboutController(windowNibName: "About")
let preferencesController = PreferencesController(windowNibName: "Preferences")

func showAbout(sender: AnyObject) {
    println("showing about window")
    aboutController.showWindow(aboutController.aboutWindow)
}

func showPreferences(sender: AnyObject) {
    println("showing preferences window")
    preferencesController.showWindow(preferencesController.preferencesWindow)
}