ios - iOS:NSNotification无法识别的选择器错误

标签 ios objective-c nsnotificationcenter

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/

相关文章:

iphone - 关于 NSDateFormatter 的困惑

iOS:如何处理已释放的委托(delegate)

objective-c - 在哪里可以找到 iOS 中 malloc() 和相关 C 函数的文档?

ios - 从详细信息转入后更新 TableView 数据

ios - 发现意外的 Mach-O header 代码 : 0x72613c21 while generating ipa file

iphone - 在联系页面添加地址簿

ios - 为什么当键盘隐藏时整个 View 会跳起来?

ios - 在 playerItem 的最后一秒暂停 AVPlayer

ios - 为什么发布通知会导致崩溃?

ios - 是否可以制作类型为 'aufc' (kAudioUnitType_FormatConverter) 的 AUv3 扩展?