【问题标题】:RPN Calculator on iOS - can't figure out why it crashesiOS 上的 RPN 计算器 - 无法弄清楚它为什么会崩溃
【发布时间】:2012-01-18 17:51:18
【问题描述】:

我是 objectiv-c 的新手,并尝试通过来自 stanford 的这个讲座播客来学习它:http://www.stanford.edu/class/cs193p/cgi-bin/drupal/ 非常好的事情,但我在构建 rpn 计算器时遇到了问题。当我使用 popOperand 时它会崩溃。

这是我的模型:

#import "CalculatorBrain.h"

@interface CalculatorBrain()
@property (nonatomic,strong) NSMutableArray *operandStack;
@end


@implementation CalculatorBrain
@synthesize operandStack = _operandStack;

-(NSMutableArray *)operandStack {
    if(_operandStack == nil) {
        _operandStack = [[NSMutableArray alloc] init];
        NSLog(@"zing");

    };
    return _operandStack; 
}




- (void) pushOperand:(double)operand {
     NSLog([[self.operandStack lastObject] stringValue] );
    [self.operandStack addObject:[NSNumber numberWithDouble:operand]];
    NSLog(@"----");
     NSLog([[self.operandStack lastObject] stringValue] );

};

-(double) popOperand {
    NSNumber* operandObject = [self.operandStack lastObject];
        if(operandObject) [self.operandStack removeLastObject];
    return [operandObject doubleValue];
}






- (double) performOperation:(NSString *)operation{
    double result = 0;
    if([operation isEqualToString:@"+"]) {
        result = [self popOperand] + [self popOperand];
    } else if([operation isEqualToString:@"*"]) {
        result = [self popOperand] * [self popOperand];

    } else if([operation isEqualToString:@"-"]) {
        double subtrahend = [self popOperand];
        result = [self popOperand] - subtrahend; 

    } else if([operation isEqualToString:@"/"]) {
        double divisor = [self popOperand];
        if(divisor) result = [self popOperand] / divisor;
}

    [self pushOperand:result];
    return result;
};



@end

真的不知道怎么做。操作数在栈上,但是popOperand好像不能访问?!

【问题讨论】:

  • 您应该发布崩溃日志和堆栈跟踪以获得适当的帮助。
  • 你能确认你正在使用 ARC 吗?
  • 哦,伙计们,大声笑。对此感到抱歉,完全是我的错:没有看到我打开了断点 - 所以应用程序停止是绝对正确的。我想我需要睡觉了

标签: iphone objective-c ios ios5


【解决方案1】:

哦,伙计们,大声笑。对此感到抱歉,完全是我的错:没有看到我打开了断点 - 所以应用程序停止是绝对正确的。我想我需要睡觉了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-01
    • 1970-01-01
    相关资源
    最近更新 更多