Could you explain better what you get and what you want ?
I try to formulate
You click button, calling obrirAmbCodi, which opens a window finestra3
when you click again on that button, a new, similar window opens (probably stacked over previous one ?)
in such a case, you would want just to display the already opened window, not create a new one.
Is that correct ?
If so, you could:
In the class where obrirAmbCodi is, declare a var
var controller: NSWindowController?
test if nil ; if so instantiate
@IBAction func obrirAmbCodi(_ sender: NSButton) {
if controller == nil {
let storyboard:NSStoryboard = NSStoryboard(name: "Main", bundle: nil)
controller = storyboard.instantiateController(withIdentifier: "finestra3") as? NSWindowController // could be nil
controller?.showWindow(self)
}
}
dismiss the controller when you close window and set to nil
Note: you could test if the window is open instead of testing controller
Topic:
Programming Languages
SubTopic:
Swift
Tags: