1

如何在 obj-C 中打印系统上的每条通知?

[[NSNotificationCenter defaultCenter] addObserver:self ...];

“...”中的内容是什么?我应该使用 NSDistributedNotificationCenter 吗?

假设我有一个名为 logfunc 的函数,它将执行 NSLog(@"ok");

谢谢你

4

1 回答 1

6
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod:) name:nil object:nil];

然后,您可以定义一个与您的选择器匹配的方法,如下所示:

- (void)myMethod:(NSNotification *)notification {
    NSLog(@"notification received: %@", notification);
}
于 2011-01-26T00:19:37.953 回答