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

Reply
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).

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.