iPhone通知会导致“未识别的选择器已发送到实例……”
-
12-10-2019 - |
题
简而言之,我正在注册以下内容 NSNotification
听众进来 ClassA
(在 viewDidLoad
):
[[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
调用方法。
有人可以在这里帮我吗?从一个控制器向另一个控制器发布通知时,我会忘记什么?
解决方案
您的 @selector
需要一个 :
角色是否要论证:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playSong:) name:@"playNotification" object:nil];
实例 ClassA
做 不是 回应 playSong
选择器,但他们 做 回应 playSong:
选择器。
不隶属于 StackOverflow