2008-11-28 88 views

回答

4

Cocoa框架中的大多數委託方法只是通知方法。這包括application{Will,Did}{Become,Resign}Active:,這是NSApplication{Will,Did}{Become,Resign}ActiveNotification的通知方法。通知與代表方法位於同一位置:the NSApplication documentation

因此,只需註冊本地NSNotificationCenter上的通知即可。

+0

謝謝,作品像魅力。我將此通知與FSEvents結合使用來刷新NSTableView。根據我的調試,一切正常,直到我在視圖上調用setDataSource。該視圖只是不更新​​。任何想法發生了什麼? – 2008-11-29 01:03:19

3

NSPreferencePane爲您提供了一些可以覆蓋以響應更改的方法。特別是,mainViewDidLoad:讓您有機會在首選項窗格變爲活動狀態時進行初始化。

如果您確實想要跟蹤系統首選項窗口變爲主鍵還是鍵值,您可以訂閱NSWindow針對這些事件的通知。

// These messages get sent to the a preference panel just before and 
// just after it becomes the currently selected preference panel. 
- (void) willSelect; 
- (void) didSelect; 

// The willUnselect message gets sent to the currently selected preference panel 
// just before and just after it gets swapped out for another preference panel 
- (void) willUnselect; 
- (void) didUnselect;