​​ ​

The Apple Support Community will permanently close on November 20, 2026. Starting today, the site will no longer accept new posts and is available in a read-only state.


You can continue to find trusted guidance and support on the official Apple Support site. 


We want to thank the community members who have contributed their time and expertise to help others with their Apple products.


Xcode Open my App when Its Icon is clicked?

I made a simple app using xcode, but it has one issue.

When I close its only window, I can't open it again. If I click the icon, nothing happens. How do I make it so the window opens every time I click the icon in the dock?

Thanks

MacBook Pro, OS X Mountain Lion (10.8.2)

Posted on Jan 25, 2013 2:55 PM

14 replies

Jan 25, 2013 4:32 PM in response to xnav

Yes, but I want the effect that, for example, Safari has. When you close all windows but do not quit the app, and click the icon in the Dock, a new window appears with you homepage. I want my app's main window to appear when I click the icon. But to answer your question, yes. When I actually quit the app and reopen it, a new window does appear.

Jan 25, 2013 7:42 PM in response to MacOSXNoob

Assuming your window is not released when it is closed, you can add the applicationShouldHandleReopen:hasVisibleWindows: method to your AppDelegate and bring your window back to the front - for example (mainWindow in the following is an outlet to your main window):


on applicationShouldHandleReopen_hasVisibleWindows_(theApplication, flag)

mainWindow's makeKeyAndOrderFront_(me)

returntrue

end applicationShouldHandleReopen_hasVisibleWindows_

Jan 25, 2013 8:12 PM in response to MacOSXNoob

Adding that delegate method will reopen your window when the Dock icon is clicked - check from the Interface Editor that the window behavior Release When Closed is unchecked, otherwise it goes away when you close it, instead of just being removed from view. I don't know how you are referencing the window, but in my example I connected the outlet mainWindow to the window (make sure you got the window and not its view).

Jan 25, 2013 8:34 PM in response to red_menace

Thank you for the help. This worked, but I decided to go with this in my delegate:

on applicationShouldTerminateAfterLastWindowClosed_(sender)    returntrueend applicationShouldTerminateAfterLastWindowClosed_

it works a lot better for my app, because it is small and has no need to stay open, so it will just quit instead. Thank you for your help

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Xcode Open my App when Its Icon is clicked?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.