iOS:在简单计算器中使用未声明的标识符错误

时间:2013-02-11 22:43:59

标签: ios objective-c compiler-errors

我收到此编译器错误“使用未声明的标识符”就像标题所说的那样。我试图写一个“结果”一个“operationPerformed”,这基本上是一些数学方程式。我是Xcode的新手,所以不要惩罚我:)。感谢你的时间!

相应编辑的代码

@interface CalculatorViewController ()

@end

@implementation CalculatorViewController
-(void)setOperand:(double)aDouble
{
    operand = aDouble;
}

-(double)performOperation:(NSString *)operation
{
    if ([operation isEqualToString:@"sqrt"])
    {
        operand = sqrt(operand);
    }
    else if ([operation isEqualToString:@"+/-"] && operand !=0)
    {
        operand = -1 * operand;
    }
    else if ([operation isEqualToString:@"1/x"] && operand !=0)
    {
        operand = 1.0 / operand;
    }

    else if ([operation isEqualToString:@"sin"])
    {
        operand = sin(operand);
    }
    else if ([operation isEqualToString:@"cos"])
    {
        operand = cos(operand);
    }
    else if ([operation isEqualToString:@"tan"])
    {
        operand = tan(operand);
    }
    else
    {
        [self performWaitingOperation];
        waitingOperation = operation;
        waitingOperand = operand;
    }
    return operand;
}

-(void)performWaitingOperation
{
    if ([@"+" isEqual:waitingOperation] )
    {
        operand = waitingOperand + operand;
    }
    else if ([@"*" isEqual:waitingOperation])
    {
        operand = waitingOperand * operand;
    }
    else if ([@"-" isEqual:waitingOperation])
    {
        operand = waitingOperand - operand;
    }
    else if ([@"/" isEqual:waitingOperation])
    {
        if(operand)
        {
            operand = waitingOperand / operand;
        }
    }
}

-(IBAction)operationPressed:(UIButton *)sender
{
    if (userIsInTheMiddleOfTypingANumber)
    {
        setOperand:[[display text] doubleValue];
        userIsInTheMiddleOfTypingANumber = NO;
        decimalAlreadyEnteredInDisplay = NO;
    }
    NSString * operation = [[sender titleLabel] text];
    double result = [self operformOperation:operation];
    [display setText:[NSString stringWithFormat:@"%f", result]];
}

1 个答案:

答案 0 :(得分:1)

这一行:

double result = performOperation:operation;

语法无效。也许你想要:

double result = [self performOperation:operation];

没有更多背景,很难说。