Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 144 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"unrecognized selector sent to instance" error in Objective-C

#11
Another really silly cause of this is having the selector defined in the interface(.h) but not in the implementation(.m) (p.e. typo)
Reply

#12
Another reason/solution to add to the list. This one is caused by iOS6.0 (and/or bad programming). In older versions the selector would match if the parameter types matched, but in iOS 6.0 I got crashes in previously working code where the name of the parameter wasn't correct.

I was doing something like

[objectName methodName:@"somestring" lat:latValue lng:lngValue];

but in the definition (both .h and .m) I had

(viod) methodName:(NSString *) latitude:(double)latitude longitude:(double)longitude;

This worked fine on iOS5 but not on 6, even the exact same build deployed to different devices.

I don't get why the compiler coudn't tell me this, anyway - problem soled.
Reply

#13

This also might happen when you want to set a property from a ControllerA to a public property inside a custom ControllerB class and you haven't set the "Custom Class" inside the identity inspector in storyboards yet.
Reply

#14
Another possible solution: Add '-ObjC' to your linker arguments.

Full explanation is here:

[To see links please register here]


I think the gist is: if the category is defined in a library you are statically linking with, the linker isn't smart enough to link in category methods. The flag above makes the linker link in all objective C classes and categories, not just ones it *thinks* it needs to based on analyzing your source. (Please feel free to tune or correct that answer. I'm knew to linked languages, so I'm just parroting here).
Reply

#15
In my case the function was not expecting an argument but the button was configured to send one causing the error. To fix this I had to rewire the event handler.

Here is my function:

![enter image description here][1]

Notice it contains no arguments.

Here is an image of my button configuration (right click on the button to view it):

![enter image description here][2]

Notice there are 3 event handlers.

To fix this I had to remove each of the event items since one of them was sending a reference to itself to the enterPressed function. To remove these items I clicked on the little x icon next to the name of each item until there were no items shown.

![enter image description here][3]

Next I had to reconnect the button to the event. To do this hold down the Control key and then drag a line from the button to the action. It should say "Connect Action". Note: I had to restart XCode for this to work for some reason; otherwise it only let me insert actions (aka create a new action) above or below the function.

![enter image description here][4]

You should now have a single event handler wired to the button event that passes no arguments:

![enter image description here][5]

This answer compliments the answer by @Leonard Challis which you should read as well.


[1]:

[2]:

[3]:

[4]:

[5]:
Reply

#16
The most obvious cause of this (included for completeness) is improperly casting a pointer and calling a method of the wrong class.

NSArray* array = [[NSArray alloc] init];
[(NSDictionary*)array objectForKey: key]; // array is not a dictionary, hence exception
Reply

#17
I'm currently learning iOS development and going through the "Beginning iOS6 Development" book by aPress. I was getting the same error in Chapter 10:Storyboards.

It took me two days to figure it out but found out I accidentally set the TableView cell's tag to 1 when I shouldn't have. For anyone else doing this book and receive a similar error I hope this helps.

I really hope future errors in my code are easier to find! hahaha. The debug error did nothing to push me in the right direction to figuring it out (or at least I'm too new to understand the debugger, lol).
Reply

#18
In my case I was using a UIWebView and I passed a NSString in the second parameter instead of a NSURL. So I suspect that wrong class types passed to a functions can cause this error.
Reply

#19
OK, I have to chip in here. The OP **dynamically created the button**. I had a similar issue and the answer (after hours of hunting) is so simple it made me sick.

When using:

action:@selector(xxxButtonClick:)

or (as in my case)

action:NSSelectorFromString([[NSString alloc] initWithFormat:@"%@BtnTui:", name.lowercaseString])

If you place a colon at the end of the string - it will pass the sender. If you do not place the colon at the end of the string it will not, and the receiver will get an error if it expects one. It is easy to miss the colon if you are dynamically creating the event name.

The receiver code options look like this:

- (void)doneBtnTui:(id)sender {
NSLog(@"Done Button - with sender");
}
or
- (void)doneBtnTui {
NSLog(@"Done Button - no sender");
}

As usual, it is always the obvious answer that gets missed.
Reply

#20
My problem and solution was different and I thought I should post it here so that future readers can save their head from banging to the wall.

I was allocating different xib to same UIVIewController and even after searching everywhere I couldn't find how to correct it. Then I checked my AppDelegate where I was calling `initWithNibName` and can see that while copying the code, I changed the xib name, but forgot to change `UIViewController` class. So if none of the solution works for you, check your `initWithNibName` method.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through