NSNotification *notification = [NSNotification notificationWithName:@"locationObtained" object:self];
[[NSNotificationCenter defaultCenter]postNotification:notification];

我得到[LocavoreRetroFirstViewController startServices]: unrecognized selector sent to instance 0x74c3070
- (void)listenForLocationCompletion{
    [[NSNotificationCenter defaultCenter]addObserver:self
                                            selector:@selector(startServices)
                                                name:@"locationObtained"
                                              object:nil];
}

- (void)startServices:(NSNotification *)notification{

}

我为什么会收到此错误?

最佳答案

改成 :

[[NSNotificationCenter defaultCenter]addObserver:self
                                            selector:@selector(startServices:)
                                                name:@"locationObtained"
                                              object:nil];
}

您的选择器startServices在末尾缺少“:”

关于ios - iOS:NSNotification无法识别的选择器错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15826266/

10-09 04:48