• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSWindowWillCloseNotification problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >NSWindowWillCloseNotification problem (From: Gideon King <email@hidden>)

  • Prev by Date: NSWindowWillCloseNotification problem
  • Next by Date: Re: NSWindowWillCloseNotification problem
  • Previous by thread: NSWindowWillCloseNotification problem
  • Next by thread: Re: NSWindowWillCloseNotification problem
  • Index(es):
    • Date
    • Thread