Re: NSWindowWillCloseNotification problem
Re: NSWindowWillCloseNotification problem
- Subject: Re: NSWindowWillCloseNotification problem
- From: John Hörnkvist <email@hidden>
- Date: Sat, 8 Dec 2001 17:31:50 +0100
On Saturday, December 8, 2001, at 05:12 , 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.
Anyone have any idea why this might be happening?
You're calling addObserver: each time doIt: is pressed.
Any way around this?
Don't call addObserver more than once, or remove the observer when the
window is closed.
Adding it in awakeFromNib or similar is usually the best.
Otherwise:
- (void)itWillClose:(NSNotification *)notification
{
NSLog(@"Closed");
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSWindowWillCloseNotification object:otherWindow];
}
Regards,
John Hornkvist
--
ToastedMarshmallow, the perfect Cocoa companion
http://www.toastedmarshmallow.com