Houman
Houman

Reputation: 66320

unrecognized selector sent to instance

I have an issue with selecting a method for a notification.

In the init I have definied this:

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

The method is definied though, both in header and same implementation:

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

However when a different class is posting this notification:

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

The hell breaks loose:

[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

Any idea what is going on here?

Upvotes: 1

Views: 1027

Answers (2)

graver
graver

Reputation: 15213

You telling that the observer's selector has a parameter:

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

and your selector doesn't have a parameter:

-(void)stopSyncIndicator

To fix, either remove the : from selector:@selector(stopSyncIndicator:) or set your method signature to:

-(void)stopSyncIndicator:(NSNotification *)notification

Upvotes: 2

wattson12
wattson12

Reputation: 11174

Your selector has a : indicating it will accept an argument, your implementation does not

either

@selector(stopSyncIndicator) //no :

or

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

would fix this

Upvotes: 6

Related Questions