Event for Red Close button of NSWindowController

Jason picture Jason · May 3, 2011 · Viewed 8.7k times · Source

How can I handle an event where I click on the red close button of a NSWindowController?

Reason for asking is that I have a video playing in a new NSWindowController window and when user clicks on the red close button, the audio continues playing, so I want to use the event to close the video.

Answer

user557219 picture user557219 · May 3, 2011

Make your NSWindowController subclass conform to the NSWindowDelegate protocol and be the delegate of the corresponding window. Having done that, implement:

- (void)windowWillClose:(NSNotification *)notification {
    // whichever operations are needed when the
    // window is about to be closed
}

in your NSWindowController subclass.