1

obj-Cでシステム上のすべての通知を印刷するにはどうすればよいですか?

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

「...」で何をしますか?NSDistributedNotificationCenterを使用する必要がありますか?

NSLog(@ "ok");を実行するlogfuncという関数があるとしましょう。

ありがとうございました

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 に答える