This Is Similar To One Of My Earlier Questions That Never Got Answered.
I would like the Dock Icon to use the method makekeyandorderfront
to open the Main window after it has been closed. I have done this with a button opening a Window but I don't know how to do it with the Dock Icon because you can't make a connection to it in interface builder.
views:
348answers:
2
+8
A:
There's a delegate method in NSApplication's delegate:
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag;
which you can use to handle clicks on the app's icon in the dock. See its documentation.
Nikolai Ruhe
2009-06-07 19:02:29
Thanks for that, What code would I need to make it open a window though?
Joshua
2009-06-08 05:43:29
Thanks for that, What code would I need to make it open a window though?
Joshua
2009-06-08 15:58:45
Please! What code would I need to make it open a window though?
Joshua
2009-06-09 06:49:47
Just to make you stop nagging: [_window makeKeyAndOrderFront:nil]; Of course you need the instance variable in the delegate's class.B.t.w.: SO is for coding questions. If you need complete code examples to copy and paste there are other sites on the web.
Nikolai Ruhe
2009-06-09 09:05:12
Sorry, what other websites are there for complete code examples?
Joshua
2009-06-09 18:45:21
What would I need to do to make the the app know what window to open when the dock is clicked?
Joshua
2009-06-10 06:06:25
+4
A:
There is another way to handle this:
Rather than try and re-open an app window by clicking in the dock you could tell the app to terminate when the last window is closed. This way, you won't have an active dock icon showing when there are no windows open.
Put this delagate method in your app delegate
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication {
return YES;
}
Which method you chose, though, is up to you and your app. I prefer to use this method with non document based apps because it doesn't make sense to have your app running when the only window for it is shut down.
Abizern
2009-06-08 00:03:12