如果一个类注册了某种类型的
如果一个类注册了某种类型的
NSNotificationCenter
事件,并且另一个类发布了该类型的事件,那么接收器中的代码会在发布类继续之前(同步)还是之后(异步)执行?如果一个类注册了某种类型的
NSNotificationCenter
事件,并且另一个类发布了该类型的事件,那么接收器中的代码会在发布类继续之前(同步)还是之后(异步)执行?- (void)poster {
[[NSNotificationCenter defaultCenter]
postNotificationWithName:@"myevent"
object:nil];
NSLog(@"Hello from poster");
}
- (void)receiver {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector:(mySelector)
name:@"myevent"
object:nil];
}
- (void) mySelector:(NSNotification *) notification {
NSLog(@"Hello from receiver");
}
在上面的代码示例中,"Hello from receiver"会在"Hello from caller"之后打印吗?