views:

494

answers:

2

It seems that I can't control the NSApp delegate from within a System Preferences pane, which is understandable. Is there any other way I can have my object notified when the program becomes active?

+3  A: 

NSPreferencePane gives you a few methods you can override to respond to changes. In particular, mainViewDidLoad: gives you a chance to do initialization when your preference pane becomes active for the first time.

If you actually meant you want to keep track of when the System Preferences window becomes main or key, you can subscribe to NSWindow's notifications for those events.

Marc Charbonneau
+4  A: 

Most delegate methods in the Cocoa frameworks are simply notification methods. This includes application{Will,Did}{Become,Resign}Active:, which are notification methods for NSApplication{Will,Did}{Become,Resign}ActiveNotification. The notifications are in the same place as the delegate methods: the NSApplication documentation.

So, just sign up for those notifications on the local NSNotificationCenter.

Peter Hosey
Thanks, works like a charm. I'm using this notification in conjunction with FSEvents to refresh an NSTableView. According to my debugging, everything works exactly as it should until I call setDataSource on the view. The view just doesn't update. Any idea what's happening?
Rich Catalano
None. You should post another question with more details.
Peter Hosey