Метод выбора NSNotificationCenter никогда не вызывается.Получение проблемы в NSNotificationCenter
PostNotification, следуют:
- (IBAction)go:(id)sender {
AnotherViewController *obj = [self.storyboard instantiateViewControllerWithIdentifier:@"AnotherViewController"];
[[NSNotificationCenter defaultCenter]
postNotificationName:@"TestNotification"
object:self];
[self.navigationController pushViewController:obj animated:YES];
}
Наблюдайте Уведомление в AnotherViewController.m:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveTestNotification:)
name:@"TestNotification"
object:nil];
// Do any additional setup after loading the view.
}
и receiveTestNotification является:
- (void) receiveTestNotification:(NSNotification *) notification
{
if ([[notification name] isEqualToString:@"TestNotification"])
NSLog (@"Successfully received the test notification!");
}
В чем проблема? Спасибо
Этот код выглядит хорошо для меня. – trojanfoe
, но не работает для меня. Контроль никогда не доходит до селекторного метода. –