无法获得可可通知工作

问题描述:

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

Apple“通知中心的工作区的通知” 之间的区别:

[[NSWorkspace sharedWorkspace] notificationCenter] 

“进程的默认通知中心”Apple

[NSNotificationCenter defaultCenter] 

您需要选择其中一个使用。

+0

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