这是在底部同时出现“双结果”和“if”的错误。
不确定为什么会发生这种情况,这是从Itunes U的一次演讲中得出的,而据我多次扫描所知,这是完全相同的。
问题
没有可见的@interface'CalculatorViewController'声明选择器'enterPressed'
#import "CalculatorViewController.h"
#import "CalculatorBrain.h"
@interface CalculatorViewController()
@property (nonatomic) BOOL userIsInTheMiddleOfEnteringANumber;
@property (nonatomic, strong) CalculatorBrain *brain;
@end
@implementation CalculatorViewController
@synthesize display = _display;
@synthesize userIsInTheMiddleOfEnteringANumber = _userIsInTheMiddleOfEnteringANumber;
@synthesize brain = _brain;
- (CalculatorBrain *)brain {
if(!_brain) _brain = [[CalculatorBrain alloc] init];
return _brain;
}
- (IBAction)digitPressed:(UIButton *)sender
{
NSString *digit = sender.currentTitle;
if(self.userIsInTheMiddleOfEnteringANumber){
self.display.text = [self.display.text stringByAppendingString:digit];
} else {
self.display.text = digit;
self.userIsInTheMiddleOfEnteringANumber = YES;
}
}
- (IBAction)enterPressed:(id)sender {
[self.brain pushOperand:[self.display.text doubleValue]];
self.userIsInTheMiddleOfEnteringANumber = NO;
}
- (IBAction)operationPressed:(UIButton *)sender {
if(self.userIsInTheMiddleOfEnteringANumber) [self enterPressed];
double result = [self.brain performOperand:sender.currentTitle];
NSString *resultString = [NSString stringWithFormat:@"%g", result];
self.display.text = resultString;
}
@end
最佳答案
你有:
if(self.userIsInTheMiddleOfEnteringANumber) [self enterPressed];
更改为:
if(self.userIsInTheMiddleOfEnteringANumber) [self enterPressed:self];
之所以出错,是因为您忘记了
(id)sender
中声明的enterPressed
参数。- (IBAction)enterPressed:(id)sender
关于ios - 没有@interface for CalculatorViewController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16641241/