The window will not be restored after it is closed.

When I launch an OS X application from Xcode, it looks as it should.

When I close the window, it disappears (as expected), and the application still appears on the dock.

Great, as it should be. But when I click on the dock to activate the window, it does not appear.

Any ideas?

+6
source share
2 answers

There is not much information in the question, but let me assume that the application is a single-window application (i.e. not NSDocument ).

A typical situation in this scenario is that the user closes the window and the application continues to work with the icon in the Dock, as expected.

In this situation, the user usually needs the window to appear again when the application is activated by clicking the icon in the dock.

To get this, you can implement applicationShouldHandleReopen:hasVisibleWindows: as follows:

 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)visibleWindows { if ( visibleWindows ) { [self.window orderFront:self]; } else { [self.window makeKeyAndOrderFront:self]; } return YES; } 
+21
source

for quick:

 func applicationShouldHandleReopen(sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { if let window = sender.windows.first { if flag { window.orderFront(nil) } else { window.makeKeyAndOrderFront(nil) } } return true } 
+3
source

Source: https://habr.com/ru/post/923673/


All Articles