從不調用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
但不適用於我。控制永遠不會到達選擇器方法。 –