Search code examples
objective-ccocoansnotification

Cocoa - finding out when a window has been closed, minimized or tabbed


how do you find out when a cocoa application has been closed, minimized or tabbed?

I have read up on NSNotifications however, I still cannot understand how I can find out when the user has done any of the 3 actions above.

Thank you for any input


Solution

  • Have your controller class conform to the NSWindowDelegate protocol and implement windowWillMiniaturize: and windowWillClose: and they will be called just before the window does the action.

    Do the same with the NSTabView delegate protocol and implement tabView:willSelectTabViewItem:.

    Some cocoa classes also send out notifications that are the same or similar to their delegate protocol, for example: NSWindow Notifications. You can use NSNotificationCenter to listen to these events. You have to look at the documentation to find out what exists.