• 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: NSWindowController that closes itself
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSWindowController that closes itself


  • Subject: Re: NSWindowController that closes itself
  • From: "John C. Randolph" <email@hidden>
  • Date: Tue, 13 Nov 2001 19:08:12 -0800

On Tuesday, November 13, 2001, at 07:08 PM, Erik M. Buck wrote:

I'm writing a NSWindowController subclass (but not one to be used for a
NSDocument). I've made it the NSWindow delegate for its window as well.

Now, when the user closes the window, being the NSWindow delegate I get
a windowWillClose, and I handle it by sending a message directly to some
object and then doing [self autorelease].

Under certain conditions, I would like to initiate the same process
myself, from within my NSWindowController subclass. I tried [[self
window] performClose:self], but when I do that, my windowWillClose
doesn't get called!

Why is that, and what should I do to overcome this?

It is probably that way because if you send a message to close the window
you probably want it to close.

However, if you can send -performClose: to a window then you can write the
following code:

if([[[self window] delegate]
respondsToSelector:@selector(windowWillClose:)])
{
if([[[self window] delegate] windowWillClose:[self window]])
{
[[self window] performClose:self];
}
}
else
{
[[self window] performClose:self];
}

Umm...

NSWindow *window = [self window];
id delegate = [window delegate];

if(delgate && [delegate respondsToSelector:@selector(windowWillClose:)])
{
if([delegate windowWillClose:window])
[window performClose:self];
}
else
[window performClose:self];

Ah, that's better. ;-)

-jcr

"Bill Gates is just a white Persian cat and a Monocle away from being the villain in a James Bond flick" - Dennis Miller


  • Follow-Ups:
    • Re: NSWindowController that closes itself
      • From: "Erik M. Buck" <email@hidden>
References: 
 >Re: NSWindowController that closes itself (From: "Erik M. Buck" <email@hidden>)

  • Prev by Date: Re: NSWindowController that closes itself
  • Next by Date: Re: AltiVec on OSX in Cocoa
  • Previous by thread: Re: NSWindowController that closes itself
  • Next by thread: Re: NSWindowController that closes itself
  • Index(es):
    • Date
    • Thread