lazyd3v
lazyd3v

Reputation: 446

New window opens incorrectly

I want to load a new window after clicking a button. This code opens new window for about 0.01 ms and close. What I'm doing wrong?

@IBAction func goToSettings(sender: AnyObject) {
    let s = SettingsViewController(windowNibName: "SettingsViewController")
    s.showWindow(sender)
}

The button is located in popover at menu bar.

Upvotes: 0

Views: 48

Answers (1)

Ken Thomases
Ken Thomases

Reputation: 90571

The controller is stored in a local variable. After your goToSettings() method exits, there's no strong reference to it anymore. So, it's released and it releases the window that it owns.

You need to store a strong reference to it in some longer-lived variable, such as an instance variable of whatever class has that goToSettings() method.

Upvotes: 2

Related Questions