NSWindowWillCloseNotification problem
NSWindowWillCloseNotification problem
- Subject: NSWindowWillCloseNotification problem
- From: Gideon King <email@hidden>
- Date: Sun, 9 Dec 2001 00:12:25 +0800
I have a window that I display when the user presses a button, and when
they close the window, I want to be notified so that I can do some stuff
when they close the window. The first time I do this, it works fine, but
the next time it fires the close notification twice, and then 3 times
etc.
I have stripped it back to something really simple:
// Called when I press the button
- (IBAction)doIt:(id)sender
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(itWillClose:) name:NSWindowWillCloseNotification
object:otherWindow];
[otherWindow makeKeyAndOrderFront:self];
NSLog(@"Displayed");
}
// Called when I close the window
- (void)itWillClose:(NSNotification *)notification
{
NSLog(@"Closed");
}
The output for multiple times opening and closing the window is:
Displayed
Closed
Displayed
Closed
Closed
Displayed
Closed
Closed
Closed
...
Anyone have any idea why this might be happening? Any way around this?
TIA
Gideon.