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

#1
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(@"---");
}
Reply

#2
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.
Reply

#3
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.

Reply

#4
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.
Reply

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

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

#7
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.
Reply

#8
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"
Reply

#9
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.
Reply

#10
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]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

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