问题
Hey I'm trying to make a clear button for my polish calculator.. code give me this error when executing the clear button
unrecognized selector sent to instance 0x6a6e1e0'
there is a button in the interface builder linked to clearBtn
this code is in the CalculatorViewController.m display is linked to the UILabel and.. heres the code
- (IBAction)clearBtn
{
if (self.userIsInTheMiddleOfEnteringANumber) {
[[self display] setText:@"0"];
[self setUserIsInTheMiddleOfEnteringANumber:NO];
}
}
- (IBAction)clearAllBtn //this button works fine..
{
[[self brain] clearAll]; // the brain class has a method to set the array to nill
[[self display] setText:@"0"];
[self setUserIsInTheMiddleOfEnteringANumber:NO];
}
回答1:
Thanks for posting the code. Generally, unrecognized selector errors are not tough, but we need to know which line of code is triggering it, which will help us understand which object is receiving the message, and what the selector is. Can you post a dump of the error messages?
Read about Objective-C selectors here.
Generally speaking, Interface Builder is a great tool for... umm, building interfaces. But you do have to be careful about connections and making sure everything is still linked up after making changes to your code or layout.
回答2:
kind of hard to know without seeing the rest of your code, but I'd assuming it's because you don't have a method named setUserIsInTheMiddleOfEnteringANumber
. Maybe double check the spelling and parameter list?
来源:https://stackoverflow.com/questions/9402621/crash-from-attempting-to-clear-a-calcuator