开发者

Cannot get Cocoa notifications to work

Settting up the observer code:

NSNotificationCente开发者_高级运维r *defaultCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
[defaultCenter addObserver:self
selector:@selector(updateLog:)
    name:@"Update Log"
  object:nil];

Sending the notification code:

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

With the method defined as:

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

The text "Update Log" does not appear in the log when the notification is sent. Thanks for any ideas for why this code is not working.


There is a difference between "the notification center for workspace notifications" Apple:

[[NSWorkspace sharedWorkspace] notificationCenter]

and "the process’s default notification center" Apple:

[NSNotificationCenter defaultCenter]

You need to pick one of those to use.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜