题
如何在OBJ-C中打印系统上的每个通知?
[[NSNotificationCenter defaultCenter] addObserver:self ...];
在“ ...”中有什么?我应该使用nsdistributednotificationcenter吗?
假设我有一个称为logFunc的函数,该函数将执行nslog(@ok ok”);
谢谢你
解决方案
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod:) name:nil object:nil];
然后,您可以定义与选择器相匹配的方法,例如:
- (void)myMethod:(NSNotification *)notification {
NSLog(@"notification received: %@", notification);
}
不隶属于 StackOverflow