XCode: How to reopen a cocoa application from dock

If you click the red cross of your cocoa application the app icon can be found by default in the dock. You have now two possibilities: Wether you terminate your app or you like to reopen the window by clicking on the icon in dock. For last one implement the method applicationShouldHandleReopen to your DAAppDelegate-file.

- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag {

[_window makeKeyAndOrderFront:self];

return YES;
}

It is also recommended that the window can be reopened by a menu item. So you can create e.g. a menu item under the main menu Window named Reopen and connect it to an IBAction Method in DAAppDelegate-file like this:

- (IBAction)menuReopenPressed:(id)sender {
    [_window makeKeyAndOrderFront:self];
}

Werbung



comments powered by Disqus

Copyright Dunkel & Iwer GbR | Datenschutzerklärung | Impressum