我是编程 iphone 应用程序的美妙世界的新手,我正在关注斯坦福大学在 iTunes U 上发布的系列文章,他们让你构建的第一个应用程序是计算器。现在,当我去运行计算器时,调试屏幕在这一行中断了 @property (nonatomic) BOOL userIsInTheMiddleOfEnteringANumber;
我已经按照教程到了 T,所以我不明白为什么我遇到问题而讲师没有。
//
// CalculatorViewController.m
// Calculator
//
// Created by Jweezy on 3/12/12.
// Copyright (c) 2012 Jweezy. All rights reserved.
//
#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)operationPressed:(UIButton *)sender {
if(self.userIsInTheMiddleOfEnteringANumber)[self enterPressed];
double result = [self.brain performOperation:sender.currentTitle];
NSString *resultString = [NSString stringWithFormat:@"%g", result];
self.display.text = resultString;
}
- (IBAction)enterPressed {
[self.brain pushOperand:[self.display.text doubleValue]];
self.userIsInTheMiddleOfEnteringANumber = NO;
}
@end
每当单击数字时应用程序崩溃并显示以下内容
Thread 1: breakpoint1.1 at the line @property (nonatomic) BOOL userIsInTheMiddleOfEnteringANumber;