What does it mean "unrecognized selector sent to instance"
in Xcode
?
-
2possible duplicate of [What does the “unrecognized selector sent to instance” error mean?](http://stackoverflow.com/questions/5152651/what-does-the-unrecognized-selector-sent-to-instance-error-mean) – Sherm Pendley Mar 28 '11 at 06:23
10 Answers
It means, method is not defined or on the other-way, calling a method on the wrong object.
classic example of this error is missing of ':' in selector call.
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self
action:@selector(DatePickerDoneClick)];
Here,
action:@selector(DatePickerDoneClick:)
is expected rather than
action:@selector(DatePickerDoneClick)

- 507
- 5
- 8
-
1Im new to iOS programming, and this answer really helped me :) its such a tiny difference that can be overlooked – alcedo Mar 29 '15 at 22:10
If you've deleted and re-created buttons on the Storyboard, you may have the button linked to two different methods: the old (deleted) one, and the new one. This has happened to me many times.
To fix: 1) In XCode/IB, view the Storyboard. 2) Click on the button that is causing the exception. 3) On the far-right panel, click the 'connector' icon. (A circle with an arrow in it, as of Apr-2015). 4) Assuming you're linking to the action "Touch Up Inside", make sure only ONE method is linked. An [x] will appear next to each, so if there are two, kill the one that no longer exists.

- 131
- 1
- 4
In my case it means I did not understand (for two days) a very simple requirement of the handler (selector, function): I had left off the ...:(NSNotification*)notification... in my selector (function).
In the end it is just a self.stupidMistake (or programming tired while trying to understand a new thing in iOs/xCode). I read the docs at apple, I read many, many here at stackoverflow and read all kinds of other pages from the search results and just kept overlooking the fact that I had: in the viewDidLoad:
[[NSNotificationCenter defaultCenter] addOberserver:self selector:@selector(myHandler:) name:@"UIApplicationWillResignActiveNotification" object:nil];
in the .h (declaration) and .m (real code) I had invented:
-(void)myHandler { ... }
This generated the unrecognized selector sent to instance (crash and debug output) at runtime (no errors or warnings in xcode). Then I spent almost two whole days trying to figure out the error and the error was:
-(void)myHandler:(NSNotification*)notification { ... }
Hope it helps anyone else stuck - it is a syntax thing (your Selector or Handler or Function or whatever you want to call it) must take a (NSNotification*) 'object' as a parameter whether you use it or not; and xcode (4.2 w/iOs SDK 5.0) does not generate any errors or warnings about this 'mistake'.

- 38,111
- 12
- 81
- 101

- 61
- 1
- 1
I think this error is due to calling a function in class which is not declared in the class.

- 6,374
- 3
- 36
- 47
It means that you have called a method on an object which does not support that method.
The reason it says 'unrecognised selector' is that method invocation is implemented by a message sending mechanism. The part of the message that contains the method name is called the selector.

- 15,547
- 6
- 61
- 83
I received this error due to not assigning the custom class to the view in the Interface Builder.
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"EventsFilterView" owner:self options:nil];
self.filters = [subviewArray objectAtIndex:0];
The variable self.filters
was assigned to the EventFilterView
class but the actual view in the xib file was not.
Hope this helps someone.
There are several reasons why this can occur:
ONE:The method is declared in the .h, but does not exist in the .m. The compiler does not complain, but during execution you face that crash.Please,Check this out:
- The method is implemented in the m.
- The method signature is exactly the same.
- There is not a semi-colon at the end of the method signature.
TWO:If you are calling a delegated method, check if this method is really implemented.
I use to have this error when I modify the signature, but I forgot to update the signature method on the implementation file .m

- 9,493
- 4
- 53
- 47
I had a similar problem and the issue was my ".m" class containing the unknown selector wasn't in the "Build Phases / Compile Sources" list. I added it and everything was fixed.

- 8,919
- 8
- 27
- 55