2010-09-15 236 views
0

Settting了觀察者代碼:無法獲得可可通知工作

NSNotificationCenter *defaultCenter = [[NSWorkspace sharedWorkspace] notificationCenter]; 
[defaultCenter addObserver:self 
selector:@selector(updateLog:) 
    name:@"Update Log" 
    object:nil]; 

發送通知代碼:

[[NSNotificationCenter defaultCenter] postNotificationName:@"Update Log" object:self]; 

利用該方法定義爲:

-(void)updateLog: (NSNotification *) notification { 
NSLog(@"Update Log"); } 

文本「更新日誌「在通知發送時不會出現在日誌中。 感謝任何想法,爲什麼此代碼無法正常工作。

+1

我討厭增加噪音,因爲我在OS X上不是Cocoa的專家,但是您確定共享工作區的通知中心與默認通知中心相同嗎? – warrenm 2010-09-15 01:26:55

回答

5

Apple「通知中心的工作區的通知」 之間的區別:

[[NSWorkspace sharedWorkspace] notificationCenter] 

「進程的默認通知中心」Apple

[NSNotificationCenter defaultCenter] 

您需要選擇其中一個使用。

+0

謝謝,現在它正在工作。 – 2010-09-15 16:54:31