我试图让NSNotifications工作。在这一刻,没有成功。NSNotification失败....为什么?
在我appDelegate.m文件我有:
[[NSNotificationCenter defaultCenter] postNotificationName:@"first" object:nil];
在我mainViewController.m,在viewDidLoad方法我有
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(firstRun)name:@"first" object:nil];
并建立了一个方法(在mainViewController.m以及):
-(void) firstRun:(NSNotification *) notification
{
NSLog(@"This works!");
}
但是,运行应用程序时,在日志中没有看到任何输出。
我的代码有什么问题?请指教。
Adri,如果您有时间,请点击下面答案旁边的复选标记,以便将此问题标记为已回答并被视为已关闭。 – 2013-04-09 21:23:34
@Mike完成!谢谢你提醒我。 – A3O 2013-04-10 07:36:56