質問へNSMutableArray
の回答を含む があります。答えは に保存されますNSString
。ユーザーがキーボードの完了ボタンをクリックしたときに、答えが正しいかどうかを確認しようとしています。
完了をクリックするたびに、実際には答えが正しいのに、常に間違っていると表示されます。
私が間違っていることを確信しています。
私も実行し、有効な答えNSLog
をNSLog
返します。if ステートメントに何か問題がありますか?
コード:
- (IBAction)checkAnswer:(UITextField *)sender
{
NSLog(@"The question's answer for the question you selected is %@", [selectedQuestion questionAnswer]);
if (answerField.text == [selectedQuestion questionAnswer])
{
// Show the correct label
[correctLabel setHidden:NO];
correctLabel.text = @"Correct!";
correctLabel.textColor = [UIColor greenColor];
}
if (answerField.text != [selectedQuestion questionAnswer])
{
[correctLabel setHidden:NO];
correctLabel.text = @"Incorrect";
correctLabel.textColor = [UIColor redColor];
}
// answerField.text = @"";
}