0Day Forums
"unrecognized selector sent to instance" error in Objective-C - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: Objective-C (https://0day.red/Forum-Objective-C)
+--- Thread: "unrecognized selector sent to instance" error in Objective-C (/Thread-quot-unrecognized-selector-sent-to-instance-quot-error-in-Objective-C)

Pages: 1 2 3


"unrecognized selector sent to instance" error in Objective-C - genotypicp - 07-21-2023

I created a button and added an action for it, but as soon as it invoked, I got this error:

-[NSCFDictionary numberButtonClick:]: unrecognized selector sent to instance
0x3d03ac0 2010-03-16 22:23:58.811
Money[8056:207] *** Terminating app
due to uncaught exception
'NSInvalidArgumentException', reason:'*** -[NSCFDictionary numberButtonClick:]: unrecognized selector sent to instance 0x3d03ac0'

This is my code:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
UIButton *numberButton = [UIButton buttonWithType:UIButtonTypeCustom];
numberButton.frame = CGRectMake(10, 435, 46, 38);
[numberButton setImage:[UIImage imageNamed:@"one.png"] forState:UIControlStateNormal];
[numberButton addTarget:self action:@selector(numberButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: numberButton];
}
return self;
}

-(IBAction)numberButtonClick:(id)sender{
NSLog(@"---");
}



RE: "unrecognized selector sent to instance" error in Objective-C - theriot309 - 07-21-2023

It looks like you're not memory managing the view controller properly and it is being deallocated at some point - which causes the `numberButtonClicked:` method to be sent to another object that is now occupying the memory that the view controller was previously occupying...

Make sure you're properly retaining/releasing your view controller.


RE: "unrecognized selector sent to instance" error in Objective-C - bacchuslikervfkeyuf - 07-21-2023

For those getting here via Google like I did, which probably pertains more to Xcode 4.2+/iOS 5+ more, what with ARC. I had the same error "**unrecognized selector sent to instance**". In my case I had a UIButton's target action set up to pass itself as the sender parameter, but later realised I didn't need it and removed that in code. So, something like:

- (IBAction)buttonPressed:(UIButton *)sender {

Was changed to:

- (IBAction)buttonPressed {

Right clicking the UIButton in question showed that the Touch Up Inside event was associated with the view controllers buttonPressed: method. Removing this and reassigning it to the modified method worked a treat.




RE: "unrecognized selector sent to instance" error in Objective-C - seemly617 - 07-21-2023

This was the top Google answer for this issue, but I had a different cause/result - I thought I'd add in my two cents in case others stumble across this problem.

I had a similar issue just this morning. I found that if you right click the UI item giving you the issue, you can see what connections have been created. In my case I had a button wired up to two actions. I deleted the actions from the right-click menu and rewired them up and my problem was fixed.

So make sure you actions are wired up right.


RE: "unrecognized selector sent to instance" error in Objective-C - clavolet287793 - 07-21-2023

I think you should use the void, instead of the IBAction in return type. because you defined a button programmatically.


RE: "unrecognized selector sent to instance" error in Objective-C - oba791 - 07-21-2023

This can also happen if you don't set the "Class" of the view in interface builder.



RE: "unrecognized selector sent to instance" error in Objective-C - elleketbg - 07-21-2023

I'm replying to Leonard Challis, since I was also taking the Stanford iOS class C193P, as was user "oli206"

"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:"

The problem was that I had the "Enter" button on the calculator connected twice,and a friend pointed out that doing an inspection of the button in the Storyboard showed that 2 entries were on the "Touch Up Inside" attributes when I right clicked on the "Enter" button. Erasing one of the two "Touch Up Inside" "Sent Events" solved the problem.

This showed that the problem is triggered (for the C193P video class on the Calculator Walkthrough on Assignment 1) as 2 sent events, one of which was causing the exception.


RE: "unrecognized selector sent to instance" error in Objective-C - washinesses87859 - 07-21-2023

I had a similar problem, but for me the solution was slightly different. In my case, I used a Category to extend an existing class (UIImage for some resizing capabilities - see this [howto][1] in case you're interested) and forgot to add the *.m file to the build target. Stupid error, but not always obvious when it happens where to look. I thought it's worth sharing...


[1]:

[To see links please register here]

"howto resize"


RE: "unrecognized selector sent to instance" error in Objective-C - squeezingqgmpyt - 07-21-2023

It can happen when you do not assign the ViewController to the ViewControllerScene in
the InterfaceBuilder. So the ViewController.m is not connected to any scene.


RE: "unrecognized selector sent to instance" error in Objective-C - colecolectomy221 - 07-21-2023

Including my share. I got stuck on this for a while, until I realized I've created a project with [ARC(Automatic counting reference)][1] disabled. A quick set to YES on that option solved my issue.


[1]:

[To see links please register here]