iphone通知导致“无法识别的选择器发送到实例...” [英] iphone notification results in "unrecognized selector sent to instance..."
问题描述
为了简短起见,我在 ClassA
中注册以下 NSNotification
监听器(在<$ c $中) c> viewDidLoad ):
To make it short, I'm registering the following NSNotification
listener in ClassA
(in 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];
这一切都会收到一条错误消息:
It all end up with an error message saying:
无法识别的选择器发送到实例
"unrecognized selector sent to instance"
playSong之前
方法被调用。
有人可以帮帮我吗?从一个控制器向另一个控制器发布通知时我忘记了什么?
Can anybody please help me out here? What am I forgetting when posting a notification from one controller to another?
推荐答案
您的 @selector
需要一个:
字符,如果它是一个参数:
Your @selector
needs a :
character if it is to take an argument:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playSong:) name:@"playNotification" object:nil];
ClassA的实例
不执行 回复 playSong
选择器,但他们做回应 playSong:
选择器。
Instances of ClassA
do not respond to the playSong
selector, but they do respond to the playSong:
selector.
这篇关于iphone通知导致“无法识别的选择器发送到实例...”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!