繁体   English   中英

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

[英]unrecognized selector sent to instance

我在选择通知方法时遇到问题。

在初始化中,我已经定义了:

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(stopSyncIndicator:) name:IOS_STOP_SYNC_INDICATOR object:nil];

不过,该方法在标头和相同的实现中均已定义:

-(void)stopSyncIndicator
{
    [indicator stopAnimating];
}

但是,当其他班级发布此通知时:

NSNotification *note = [NSNotification notificationWithName:IOS_STOP_SYNC_INDICATOR object:nil];
[[NSNotificationCenter defaultCenter] postNotification:note];

地狱破裂了:

[FTRecordViewController stopSyncIndicator:]: unrecognized selector sent to instance 0x8d3bc00
2013-11-18 13:47:06.994 [1835:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FTRecordViewController stopSyncIndicator:]: unrecognized selector sent to instance 0x8d3bc00'
*** First throw call stack:
(
    0   CoreFoundation                      0x01bf75e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x018f88b6 objc_exception_throw + 44
    2   CoreFoundation                      0x01c94903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275

知道这里发生了什么吗?

您的选择器带有一个:表示它将接受一个参数,而您的实现则没有

要么

@selector(stopSyncIndicator) //no :

要么

-(void)stopSyncIndicator:(NSNotification *)notification //accept argument 

会解决这个问题

您告诉观察者的选择器有一个参数:

[nc addObserver:self selector:@selector(stopSyncIndicator:) name:IOS_STOP_SYNC_INDICATOR object:nil];`<br/>

而且您的选择器没有参数:

-(void)stopSyncIndicator

要解决,或者删除:selector:@selector(stopSyncIndicator:)或设置你的方法签名:

-(void)stopSyncIndicator:(NSNotification *)notification

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM