0

is there any way to detect when a cocoa window has been closed, hidden and/or the user has changed the tab on which he was before?

animuson
  • 53,861
  • 28
  • 137
  • 147
Kevin
  • 1,469
  • 2
  • 19
  • 28

1 Answers1

1

you could use notifications to broadcast such information throughout your application:

NSNotificationCenter Class Reference

you can find some good information & examples in the iTunes U podcasts of brad larson.

this one here is a pretty great tutorial as well: http://cocoawithlove.com/2008/06/five-approaches-to-listening-observing.html

an absolut basic tutorial example can be found here: http://agilewarrior.wordpress.com/2012/02/09/dead-simple-nsnotification-example-iphone/

Sebastian Flückiger
  • 5,525
  • 8
  • 33
  • 69
  • So using a notification, I can specify the 'event' (i.e. window hidden / window closed / etc) ? I will have a look at the documentation on NSNotification and check out the iTunes U Podcast – Kevin Mar 22 '12 at 16:48
  • you can create a notificationcenter, let your classes 'listen' to notifications of that center. within your code you will be able to broadcast a notification to the center and the 'listeners' wil be able to react on it =) – Sebastian Flückiger Mar 22 '12 at 16:50
  • i added another link to my answer - a great tutorial & example on notifications =) – Sebastian Flückiger Mar 22 '12 at 16:51
  • Thank you! Marked as the answer (when the site allows me to do so :)! – Kevin Mar 22 '12 at 16:52
  • Thanks for all the resources Sebastien. However, I still cannot understand how I can call the observer when one of the actions above happen. How can I know that a window has been closed/hidden or tabbed? – Kevin Mar 27 '12 at 04:56
  • Regarding the closing of the window I've found the notification NSWindowWillCloseNotification which seems to be doing the trick.. Any other help regarding the other 2 actions? Thanks! – Kevin Mar 27 '12 at 05:23
  • NSWindowDidResignKeyNotification does the trick for minimizing the window... However for moving from tab to tab, I'm still finding some problems... – Kevin Mar 27 '12 at 05:34