我开发了一个简单的计算器应用程序。 就实际目的而言。 我采用一种“国际行动”方法,储存用户输入的数位数。 整个概念是,计算器在投影之前对碎块进行过滤,以便用户能够采取多种行动,屏幕显示其结果如下:1+ 2 - 4 + 10 = X. 因此,即有2个NSMutableArray,储存NSNumber号和操作者行动。 当用户点击运营商纽顿时,为新数字创造了一个新的阵列。 当用户进入数字时,最后一个阵列元素正在更新,直到操作者纽顿受到压力。
The problem is that every array element is zero. Inside the method it stores the corrent value when i set it, but when the method is executed and called again it contins nothing but zeros instead of the entered numbers. The NSNumber objects are present, the array contains every number, but every number is 0.
这里的方法是:
// Processing digit buttons
- (IBAction)clickDigit: (UIButton *) sender {
double currentNumber = [[numbers lastObject] doubleValue];
// Get the digit
double digit = sender.tag;
// Do nothing when the currentNumber and the digit both zero
if(currentNumber == 0 && digit == 0) {
return;
}
// When currentNumber is zero, override the value
if(currentNumber == 0) {
currentNumber = digit;
[numbers removeLastObject];
[numbers addObject: [NSNumber numberWithDouble: currentNumber ]];
// Else, add the digit to currentNumber
} else {
currentNumber = currentNumber * 10 + digit;
[numbers removeLastObject];
[numbers addObject: [NSNumber numberWithDouble: currentNumber ]];
}
// Update the screen
[self updateDisplay];
}
I have no clue what s wrong. Any suggestions? Thanks in advance
<>UPDATE:指点击 每顿报后自动使用明确的方法。 该数值为零。 我在评论部分将全部来源代码与这一员额联系起来。 唯一的问题是:为什么使用这种方法? 所谓的这种方法是什么?
UPDATE2: with The Saad s help i managed to solve this problem. Thanks to everyone! :)