NSNotification失败....为什么?

A3O*_*A3O -1 objective-c nsnotificationcenter ios

我正在努力让NSNotifications发挥作用.此刻,没有成功.

在我的appDelegate.m文件中,我有:

[[NSNotificationCenter defaultCenter] postNotificationName:@"first" object:nil];
Run Code Online (Sandbox Code Playgroud)

在我的mainViewController.m中,在viewDidLoad方法中我有

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(firstRun)name:@"first" object:nil];
Run Code Online (Sandbox Code Playgroud)

并创建了一个方法(在mainViewController.m中也是如此):

-(void) firstRun:(NSNotification *) notification
{
        NSLog(@"This works!");
}
Run Code Online (Sandbox Code Playgroud)

但是,在运行应用程序时,我在日志中看不到任何输出.

我的代码出了什么问题?请指教.

Mar*_*ski 5

错误的选择器应该是:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(firstRun:)name:@"first" object:nil];
Run Code Online (Sandbox Code Playgroud)