Recognize when the user closes the window (when the close button is clicked)
2 answers
I am using it in viewcontroller
//initWithNibName
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowWillClose:) name:NSWindowWillCloseNotification object:self.view.window];
- (void)windowWillClose:(NSNotification *)notification
{
NSWindow *win = [notification object];
//...
}
+12
source to share
You can declare your own class to be protocol compliant NSWindowDelegate
.
Set an instance of your custom class as your window delegate
Then use one of these methods (perhaps windowWillClose: one) to do something before the window is closed.
- (BOOL)windowShouldClose:(id)sender
- (void)windowWillClose:(NSNotification *)notification
+1
source to share