我正在开发一个应用程序,它在播放系统声音后对本机c函数进行回调。我希望在发生这种情况时举起一个事件,因此我视图上的订阅者可以处理它。
-(void) completionCallback(SystemSoundID mySSID, void* myself) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"SoundFinished" object: myself];
}
我收到unrecognized selector sent to instance ...
在视图中,我有以下代码:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(soundStopped) name:@"SoundFinished" object:nil];
...
-(void) soundStopped: (NSNotification*) notification {
NSLog(@"Sound Stopped");
}
我对Objective-c非常陌生,我哪里出错?
更新确切的错误是:
2011-04-18 19:27:37.922 AppName[5646:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BackgroundTestViewController soundStopped]: unrecognized selector sent to instance 0x13b4b0'
答案 0 :(得分:3)
-soundStopped
和-soundStopped:
是两种不同的方法名称。冒号是方法名称的一部分,但您在调用-addObserver:selector:name:
时将其删除。
答案 1 :(得分:2)
问题出在您的通知处理程序中(您已注册了一个未由观察者处理的选择器)。向我们展示如何添加观察者。从“普通C”功能发送通知没有问题。