Reputation: 3
Sorry for this common error.
But I am creating a convertor application in X-Code 4.6
I am creating a binary to decimal converter and I want to be able to put two areas to do calculations on. But for some reason this is giving me a Signal abort issue.
I have tried searching for some answers, but I have learnt that this error is has a massive scope, so is there someone able to assist me, I am only beginner at iOS Programming.
Error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[BinaryToDecimal calculation]: unrecognized selector sent to class 0x7c98'
The interface of the application contains 8 buttons so that the user can switch each button to a one or zero.
So the first code called is;
- (IBAction)chk1:(id)sender {
if(chk1)
{
number = number + 1;
[_chk1 setTitle:@"1" forState:UIControlStateNormal];
chk1 = false;
} else {
number = number - 1;
[_chk1 setTitle:@"0" forState:UIControlStateNormal];
chk1 = true;
}
[[self class]calculation];
}
and calculation is
- (void)calculation {
switch (operatorVar) {
case 1:
answer = number + number2;
_output.text = [NSString stringWithFormat:@"%f", answer];
break;
case 2:
answer = number - number2;
_output.text = [NSString stringWithFormat:@"%f", answer];
break;
case 3:
answer = number * number2;
_output.text = [NSString stringWithFormat:@"%f", answer];
break;
case 4:
answer = number / number2;
_output.text = [NSString stringWithFormat:@"%f", answer];
break;
default:
answer = number + number2;
_output.text = [NSString stringWithFormat:@"%f", answer];
break;
}
}
Before I was doing that my code was
- (IBAction)chk1:(id)sender {
if(chk1)
{
number = number + 1;
[_chk1 setTitle:@"1" forState:UIControlStateNormal];
chk1 = false;
} else {
number = number - 1;
[_chk1 setTitle:@"0" forState:UIControlStateNormal];
chk1 = true;
}
_output.text = [NSString stringWithFormat:@"%f", number];
}
That code above worked fine, but When I called the calculation method, the signal abort error stopped the application from working.
Upvotes: 0
Views: 293
Reputation: 3960
According to the Error description you shared, you are calling method calculation
as a Class method but your method calculation
is a instance method.
use [self calculation];
Upvotes: 2
Reputation: 640
I Think problem is
[_chk1 setTitle:@"1" forState:UIControlStateNormal];
This statement
_chk1 is button object once crass check.
other wise use this statement for button Action method like this
better use the method like " -(IBAction)buttonTouched:(UIButton *)sender" and Maintain the naming convention for each object you have declare all object same for exe: method name , button object, bool value also don't write code like that ...........
(IBAction)chk1:(UIButton*)sender {
if(chk1) { number = number + 1;
[sender setTitle:@"1" forState:UIControlStateNormal];
chk1 = false;
} else {
number = number - 1;
[sender setTitle:@"0" forState:UIControlStateNormal];
chk1 = true;
}
_output.text = [NSString stringWithFormat:@"%f", number];
}
Upvotes: 0