Reputation: 49451
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.
Upvotes: 4
Views: 3096
Reputation: 64022
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.
Upvotes: 9
Reputation: 86691
Surely, if the user closes a window they want it to go away. Reopening a window they just closed will most likely annoy them. If you, the programmer, disrespect their wishes, they will probably disrespect your program by moving it to the Trash.
If you want to make it impossible to close the main window, disable the close button. You can do this easily in interface builder on the Window attributes inspector.
Upvotes: 5