Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa: programmatically show the main window after closing it with X

I want to programmatically re-open the main window of my Cocoa application after the user closed it with the X button. I know it's still somewhere in memory but I don't know where.

like image 228
Nathan H Avatar asked Dec 09 '22 08:12

Nathan H


1 Answers

If you're using the default Cocoa Application template, your app delegate has a reference to the window that's in MainMenu.xib. You can simply call

[window makeKeyAndOrderFront:self];

perhaps in an IBAction triggered by a menu item, to reopen the window. Note: be sure that the "Release when closed" and "One shot" boxes are unchecked in IB.

like image 119
jscs Avatar answered Jan 19 '23 00:01

jscs