【发布时间】:2010-12-23 23:58:20
【问题描述】:
简而言之,我在ClassA(viewDidLoad)中注册了以下NSNotification 侦听器:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playSong) name:@"playNotification" object:nil];
我在ClassA.h 中声明了选择器:
- (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];
这一切都以一条错误消息告终:
“发送到实例的无法识别的选择器”
在调用playSong 方法之前。
有人可以帮我吗?从一个控制器向另一个控制器发布通知时我忘记了什么?
【问题讨论】:
标签: iphone objective-c ios nsnotificationcenter