NSUserDefaultsDidChangeNotification 在应该触发时没有触发或者根本没有?
在我的应用程序中,我已在 awakeFromNib 中注册了 NSUserDefaultsDidChangeNotification 通知以及其他通知(工作正常)。我如下所示注册它,这似乎是正确的:
- (void)awakeFromNib
{
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(myAction:) name:NSUserDefaultsDidChangeNotification object:nil];
}
并且我的操作方法似乎格式也正确:
- (void)myAction:(NSNotifcation*)notifcation
{
NSLog(@"foo);
}
但是,由于未知的原因,它根本拒绝触发。无论应用程序的默认设置发生了多少变化,它都不会触发一次。是我注册错误还是其他原因?过去还有其他人遇到过这个问题吗?
In my application, I have registered the NSUserDefaultsDidChangeNotification notification in awakeFromNib along with my other notifications (which are working fine). I register it just as shown below, which appears to be correct:
- (void)awakeFromNib
{
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(myAction:) name:NSUserDefaultsDidChangeNotification object:nil];
}
and my action method appears to be correctly formatted as well:
- (void)myAction:(NSNotifcation*)notifcation
{
NSLog(@"foo);
}
For unknown reasons, however, it refuses to fire at all. No matter how many of the application's defaults are changed, it never fires even once. Am I registering wrong or is something else the cause? Has anybody else experienced this problem in the past?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用
[NSNotificationCenter defaultCenter]
而不是工作区通知中心?Have you tried using
[NSNotificationCenter defaultCenter]
instead of the workspace notification center?