19

how can I take notice when an NSWindow should or will get closed? I'd like to have something like the windowWillClose. Unfortunately NSWindowController does not have as much convenient methods as UIViewController has, for example. So what's the best practice to do that?

Thanks
–f

skaffman
  • 398,947
  • 96
  • 818
  • 769
flohei
  • 5,248
  • 10
  • 36
  • 61

1 Answers1

28

According to the NSWindow docs, a window will post a NSWindowWillCloseNotification notification when it is about to close. Your controller can observe this notification.

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
  • 14
    It will also send its delegate a `windowWillClose:` message: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSWindowDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSWindowDelegate/windowWillClose: So, Cocoa does have something very much like `windowWillClose:`. ☺ – Peter Hosey Nov 26 '10 at 17:52
  • 2
    is there such thing as `windowDidClose`? – Tony Feb 03 '12 at 19:41
  • 1
    There is no such thing as windowDidClose. You have to listen for NSWindowWillCloseNotification or the delegate windowWillClose. – jdumay Nov 18 '12 at 01:24
  • 9
    Keep in mind that if you are running with `NSApplicationActivationPolicyProhibited` in order to hide the dock icon, then none of the delegate methods get called, and the notifications don't get sent. – Scott Allen Oct 02 '13 at 22:45