Reputation: 523
In my menu bar app, I have a menu item which opens a window. The window opens in the front with the window behind it remaining the key window.
I can't get window.makeKey()
to work unless I run it after a breakpoint. I tried putting the line of code in different places in the window's life cycle and even put it in DispatchQueue.main.asyncAfter(deadline: execute:)
and it didn't work.
I have also tried using window.makeKeyAndOrderFront(sender:)
. The property window.canBecomeKey
is true.
Upvotes: 2
Views: 1125
Reputation: 523
Turns out I needed to put this line in the IBAction for the menu item that opens the window:
NSApplication.shared.activate(ignoringOtherApps: true)
That makes it the key window when it opens, so I don't have to call window.makeKey()
Upvotes: 7