josh
josh

Reputation: 75

NSWindow Flashing

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.

Upvotes: 1

Views: 174

Answers (1)

Leo Dabus
Leo Dabus

Reputation: 236498

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)
}

Upvotes: 1

Related Questions