Если класс регистрирует события 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»?
просто посмотрите http://stackoverflow.com/questions/1900352/what-is-nsnotification –
прочитайте исходное сообщение ниже ответа ..http: //stackoverflow.com/questions/7880742/ios-are- методы-by-by-delegates-and-observers-execute-on-the-the-main-thread – BhushanVU