Window handling from the dock icon (Objective-C / Xcode)

I should probably post this stuff to stackoverflow, however I find that most of the people on there are rude and spend far too much time just berating anyone who asks for the slightest help. I apologise for anyone who had to waste time looking a little bit longer for this tip.

The default behaviour for a cocoa window when it’s closed with cmd+w or pressing the red X button is for the window to be closed ((but not destroyed) this applies to the main window, others may be created to release etc..). This means that the window simply needs being passed the makeKeyAndOrderFront: method to be made visible when its dock icon is clicked on:


-(BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
if (flag)
 NSLog(@"Window already open");
  } else {
   [_window makeKeyAndOrderFront:self];
 return YES;

Leave a Reply

Your email address will not be published. Required fields are marked *