我在计算器应用程序中使用 Xcode 4.6 时遇到三个错误,您能解释一下可能导致它们的原因吗?
这是3个错误
在对象类型“CalculatorBrain”上找不到属性“pushElement”,
在对象类型 CalculatorviewController 上找不到属性“按下输入”
在对象类型“CalculatorBrain”上找不到属性“执行操作”
这是我在其中遇到错误的代码的一部分CalculatorviewController.m
- (IBAction)enterPressed:(UIButton*)sender {
[_Brain.pushElement :self.display.text]; ......first error ....
userIntheMiddleOfEnteringText= NO;
}
- (IBAction)operationPressed:(UIButton *)sender {
if (userIntheMiddleOfEnteringText)
self.enterPressed; ........second error.....
else {
double result = [_Brain.performOperation]; ... third error...
self.display.text=[NSString stringWithFormat:@"%g",result];
}
}
CalculatorBrain.m
代码是
#import "CalculatorBrain.h"
@implementation CalculatorBrain
-(void)pushElement:(double)operand {
NSNumber *operandObject=[NSNumber numberWithDouble:operand];
[self.stack addObject:operandObject];
}
-(double) popElement {
NSNumber *popedNumber=[self.stack lastObject];
if (popedNumber)
{
[_stack removeLastObject];
}
return [popedNumber doubleValue];
}
-(double)performOperation:(NSString*)operation {
double result = 0;
if( [operation isEqualToString: @"+"]){
result =self. popElement + self.popElement;
}
else if ([operation isEqualToString: @"*"]){
result=self.popElement*self.popElement;
}
else if ([operation isEqualToString:@"-" ]) {
double operand=self.popElement;
result=self.popElement - operand ;
}
else if ([operation isEqualToString:@"/"]) {
double divisor =self.popElement;
result= self.popElement/ divisor;
}
return result;
}
@end