检测NSWindow关闭
You can declare your custom class to conform to NSWindowDelegate
protocol.
Set an instance of your custom class to be the delegate of your window
Then use one of these methods (probably the windowWillClose: one) to do something before the window closes.
- (BOOL)windowShouldClose:(id)sender
- (void)windowWillClose:(NSNotification *)notification