我想比较一个 int 和一个字符串,但我的代码不起作用。这是我的代码:
NSLog(@"enterPressed was called");
int answer = firstNumber + secondNumber;
NSLog(@"Real Answer: %d", answer);
NSString *numberFromTextField = inputTextField.text;
NSLog(@"Number From Text Field: %@", numberFromTextField);
if (numberFromTextField == [NSString stringWithFormat:@"%d", answer]) {
NSLog(@"Correct!");
}
这是控制台:
2012-12-09 13:10:55.087 MathQuiz[10728:c07] enterPressed 被调用
2012-12-09 13:10:55.087 MathQuiz[10728:c07] 真实答案:60
2012-12-09 13:10:55.088 MathQuiz[10728:c07] 文本字段中的数字:60
为什么不说“正确!”?