Opening and Closing Windows

This article describes how to open and close a window.

Opening a window—that is, making a window visible—is normally accomplished by placing the window into the application's window list by invoking one of the methods makeKeyAndOrderFront:, orderFront:, etc., in NSWindow, and so on. Also, with certain bits set in Interface Builder, the window is shown when the nib file is loaded in some cases.

Closing a window involves explicit use of either the close method, which simply removes the window from the screen, or performClose:, which highlights the close button as though the user clicked it. Closing a window involves at least removing it from the screen but may include disposing of it altogether. The setReleasedWhenClosed: method specifies whether a window releases itself when it receives a close message. A window’s delegate is also notified when it’s about to close, as described in “Using Window Notifications and Delegate Methods.”

These methods hide a window without closing it. The method orderOut: removes a window from the screen. You can also set a window to be removed from the screen automatically when its application isn’t active using setHidesOnDeactivate:. The isVisible method returns whether a window is on or off the screen.