Question

Bellow is the code i am calling when i press a button. The button will call the method bellow. But i get a "unrecognized selector sent to instance" error. What am i doing wrong? The objects have been declared in another method before this one is called. I have also tried hiding the buttons but they also crash. Someone please help.

-(void) clearControlPannel{

    [buttCheck removeFromSuperview];
    [buttBet removeFromSuperview];
    [buttCall removeFromSuperview];
    [buttRaise removeFromSuperview];
    [buttFold removeFromSuperview];
    [betLabel removeFromSuperview];
    [betSlider removeFromSuperview];

}

The crash is:

Thread 1: EXC_BAD_ACCESS" on the [buttCheck removeFromSuper]; line

-[__NSCFDictionary removeFromSuperview]: unrecognized selector sent to instance 0x686b020 2012-06-24 19:08:12.175 HeadsUp[59630:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary removeFromSuperview]: unrecognized selector sent to instance 0x686b020'

Was it helpful?

Solution

unrecognized selector sent to instance

error is due to the fact that the runtime is not able to find the method that will respond to that specific action. In other words, it's not able to map the name of your method (the selector) with its implementation.

So, if you have a method that accept no parameter like yours

- (void) clearControlPannel {...}

the selector will be only clearControlPannel.

Otherwise, if you have specified a parameter for that method (e.g. like the sender, the UIButton in this case) like

- (void) clearControlPannel:(id)sender {...}

the selector would be clearControlPannel:. Pay attention to :.

If you provide more details we could help you.

EDIT

Just for pointing you in the right direction.

If you have used – addTarget:action:forControlEvents: on a UIButton instance you have to check two things.

First, did you set up the target correctly? The target is the object to which the action will be redirected.

Second, did you set up the right selector for that action?

Here an example:

[myButton addTarget:self action@selector(mySelector:) ...];

where

- (void)mySelector:(id)sender {...}

If the class where you have implemented that button will also respond to that action use self, otherwise you need to inject some other instance that will respond for that action.

OTHER TIPS

Check wheather you are releasing the button which you are pressing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top