• 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: Jeff Gilbert <email@hidden>
  • Date: Sat, 8 Dec 2001 12:31:38 -0600

Hi Gideon,

You need to remove your observer of the window when it closes; something like:

// Called when I close the window
- (void)itWillClose:(NSNotification *)notification
{
// stop listening for the window to close
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowWillCloseNotification object:otherWindow];

NSLog(@"Closed");
}

The next time you click the button, you will start listening to the window again.

enjoy,
Jeff Gilbert

On Saturday, December 8, 2001, at 10: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.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


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

  • Prev by Date: Re: The sick power!
  • Next by Date: PB error
  • Previous by thread: Re: NSWindowWillCloseNotification problem
  • Next by thread: %* format doesn't work in NSLog
  • Index(es):
    • Date
    • Thread