Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window won't restore after it is closed

Tags:

cocoa

When I fire up my OS X app from Xcode, it appears as it should.

When I close the window, it disappears (as you would expect), and the app still appears active on the dock.

Great, that's how it should be. But when I click the dock to activate the window, it doesn't show up.

Any ideas?

like image 520
theiOSDude Avatar asked Aug 24 '12 14:08

theiOSDude


People also ask

Why is my restore point not working?

Sometimes restore point might not work due to corrupted files and folders on your drive, and to fix the corrupted files, you might need to check your hard drive. This process can take a while, so be patient. You might have to restart your computer to complete the disk-checking process.


1 Answers

There isn't much information in the question, but let me presume that the app is a single-window app (i.e., not NSDocument-based).

A typical situation in this scenario is that the user closes the window, and the appliction keeps running with the icon in the Dock as it is supposed to.

In that situation, the user would normally like the window to re-appear when the app is activated by clicking the icon in the Dock.

To obtain that, 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;
}
like image 64
Monolo Avatar answered Sep 23 '22 12:09

Monolo