iphone通知导致"无法识别的选择器发送到实例..."

esb*_*enr 13 iphone objective-c nsnotificationcenter ios

为了简短起见,我NSNotificationClassA(in viewDidLoad)中注册了以下监听器:

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

我有选择器声明ClassA.h:

- (void)playSong:(NSNotification *) notification;
Run Code Online (Sandbox Code Playgroud)

实施如下:

- (void)playSong:(NSNotification *) notification {
    NSString *theTitle = [notification object]; 
    NSLog(@"Play stuff", theTitle);
}
Run Code Online (Sandbox Code Playgroud)

ClassB(在tableView:didSelectRowAtIndexPath:方法中)我有:

NSInteger row = [indexPath row];
NSString *stuff = [playlistArray objectAtIndex:row];
[[NSNotificationCenter defaultCenter] postNotificationName:@"playNotification" object:stuff];
Run Code Online (Sandbox Code Playgroud)

最后都会收到一条错误消息:

"无法识别的选择器发送到实例"

playSong调用方法之前.

有人可以帮帮我吗?从一个控制器向另一个控制器发布通知时我忘记了什么?

Jac*_*kin 41

如果需要参数,你@selector需要一个:角色:

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

实例ClassA来的回应playSong选择,但他们的回应playSong:选择.