Reputation: 325
I have a problem. In my mac osx app I have a mainwindow. This window is opening initial. I am working with storyboard. But there are moments when the user needs to login again into the app. If this is the case (for example when the session ends) I open a new small window modally with this code:
private func openLogin() {
loginController = self.storyboard?.instantiateController(withIdentifier: "LoginController") as? LoginWindowController
guard let window = loginController?.window else {
return false
}
NSApp.runModal(for: window)
}
after I once opened this window and close it again I can never close the main window. If the login window never opened, there is no problem and I can close the MainWindow. But if I opened the loginwindow once, I cannot close the mainwindow. I can click on the close button but it does nothing.
And, I cannot assure this but, I think that I cannot close any window after that.
Do you have any idea?
Thank you for your Help!
Artur
Upvotes: 0
Views: 97
Reputation: 325
Ok, I have found the issue...
I called the code function openLogin()
inside of the windowDidLoad()
function of the NSWindowController
. The problem is that the applicationDidFinishLaunching
of the appDelegate will first be called after the windowDidLoad
function finished, which is logically correct.
I stopped the mainThread by running a window modally. Somehow the framework doesn´t like this before the app has completed the launch process.
I solved this by using the NSNotificationCenter
and observe the notification name NSApplicationDidFinishLaunching
. On that I run the openLogin()
code.
Upvotes: 0