我正在尝试让我构建的计算器应用程序在检测到我按下小数点按钮时触发一些简单的代码(每个值只允许一个小数点)。但是,由于某种原因,这些关于 digit 的 if 语句没有被触发。我已经 NSLogged 它的输出,它确实显示为“。” 所以我不太明白为什么。我已经改变了 . 对于任何其他值,似乎没有什么能触发它们。
NSString *digit = [sender currentTitle];
if (self.userIsInTheMiddleOfEnteringANumber) {
self.display.text = [[[self display] text] stringByAppendingString:digit]; // All in one line!
NSLog(@"Digit is equal to %@",digit);
if (digit == @".") NSLog(@"That was a decimal point!");
} else {
self.display.text = digit;
if (digit == @".") NSLog(@"You can't begin a number with a decimal!");
self.userIsInTheMiddleOfEnteringANumber = YES; // If they aren't typing, now they are!
}