iPhone的通知结果在“无法识别的select器发送到实例…”

为了简短NSNotification ,我在ClassA注册了下面的NSNotification监听器(在viewDidLoad ):

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playSong) name:@"playNotification" object:nil]; 

我在ClassA.h声明了select器:

 - (void)playSong:(NSNotification *) notification; 

并执行如下:

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

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

 NSInteger row = [indexPath row]; NSString *stuff = [playlistArray objectAtIndex:row]; [[NSNotificationCenter defaultCenter] postNotificationName:@"playNotification" object:stuff]; 

这一切都结束了一个错误消息说:

“发送给实例的无法识别的select器”

playSong方法被调用之前。

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

如果需要参数,则您的@selector需要一个:字符:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playSong:) name:@"playNotification" object:nil]; 

ClassA实例响应playSongselect器,但它们响应playSong:select器。