正如標題所示,我收到此編譯器錯誤「使用未聲明的標識符」。我試圖給「結果」寫一個「operationPerformed」,它基本上是一些數學方程式。我是Xcode的新手,所以不要懲罰我:)。感謝你的時間!iOS:在簡單計算器中使用未聲明的標識符錯誤
代碼編輯相應
@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]];
}
請顯示*確切*錯誤消息。在這種情況下,它確切地告訴你問題是什麼。 – 2013-02-11 22:45:52
好的,我解釋一下*** ***最後***時間:它不是Xcode,錯誤,它是編譯器,而且從不知道有多少人被濫用,並會濫用那個可憐的「xcode」標籤,它會保持原樣, IDE,它不會神奇地成爲編譯器。 – 2013-02-11 22:46:58
知道確切的消息,以及它標記的線會非常有幫助。 – 2013-02-11 22:48:21