Re: NSWindowWillCloseNotification problem
Re: NSWindowWillCloseNotification problem
- Subject: Re: NSWindowWillCloseNotification problem
- From: Gideon King <email@hidden>
- Date: Sun, 9 Dec 2001 00:36:41 +0800
Amazing what posting to the list does for problem solving skills...
I figured it out as soon as I posted it - I was registering multiple
times for the notification, so I was getting multiple notifications. It
obviously doesn't check whether you have already registered the same
thing. I moved it to my awakeFromNib, and it works fine.
Gideon
On Sunday, December 9, 2001, at 12:12 AM, Gideon King wrote:
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.