【问题标题】:iOS: Use of undeclared identifier error in simple calculator [closed]iOS:在简单计算器中使用未声明的标识符错误[关闭]
【发布时间】:2013-02-11 22:43:58
【问题描述】:

正如标题所说,我收到此编译器错误“使用未声明的标识符”。我正在尝试将“结果”写入“操作执行”,这基本上是一些数学方程式。我是 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]];
}

【问题讨论】:

  • 请显示准确错误信息。在这种情况下,它会准确地告诉您问题所在。
  • 好吧,我解释一下 last 时间:出错的不是 Xcode,而是编译器,别管人们滥用了多少次并将滥用那个可怜的“xcode”标签,它会保持原来的样子,一个IDE,它不会神奇地变成一个编译器。
  • 了解确切的消息,以及它标记的行,会有很大帮助。

标签: ios objective-c compiler-errors


【解决方案1】:

这一行:

double result = performOperation:operation;

是无效的语法。也许你想要:

double result = [self performOperation:operation];

没有更多的上下文很难说。

【讨论】:

  • 是的,大概就是这样。或至少其中之一。
  • 我已经更新了代码,你的回答在这种情况下又出现了一个错误
  • 你还有一本类似的:setOperand:[[display text] doubleValue];我觉得你应该买一本初学者的书。
  • 我会,虽然我是 obj-c 的临时人员(ps。有什么建议吗?)。但更重要的是,我该如何解决这个问题?这样我就可以成功编译代码并进行计算?
  • 什么?第二个问题的解决方案与第一个问题完全相同。你为什么不以同样的方式修复它?我们不是来为你做你的工作的。
猜你喜欢
  • 2023-03-19
  • 2020-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多