我对Objective c很陌生,当我遇到困难时,我会通过使用谷歌等慢慢学习,但我被这个卡住了好几个小时。我正在做一个基本测验,答案是数字。我有2个数组问题和答案,我将阵列索引在一起,NSLOG表明它们是对的,但是我的代码只是在选择正确的答案时就不同意。答案总是错误的,即使你 nslogs 说它是对的。谢谢你的帮助
_arrayQuestions = [[NSArray alloc] initWithObjects:
@"what is johns age?",
@"What is daves age ",
nil];
_arrayAnswers = [[NSArray alloc] initWithObjects:
@"32",@"42",
nil];
- (void)setQuestions {
currentQuestionIndex++;
if (currentQuestionIndex == [_arrayQuestions count]) {
currentQuestionIndex = 0;
}
NSString *question = [_arrayQuestions objectAtIndex:currentQuestionIndex];
NSLog(@"displaying question: %@", question);
[_questionLabel setText:question];
// NSLog(@"current answers: %@",[ _arrayAnswers objectAtIndex:currentQuestionIndex]);
}
- (void)checkingAnswers {
// usersAnswer = _DateField.text ;
answer = [_arrayAnswers objectAtIndex:currentQuestionIndex];
// int intAnswer = [answer intValue];
// NSLog(@"answer = : %@", usersAnswer );
NSLog(@"answer = : %@", _DateField.text);
NSLog(@"answer = : %@", answer);
if ( _DateField.text == answer) {
NSString *rightAnswer = [[NSString alloc] initWithFormat:@"Correct" ];
[_answerLabel setText : rightAnswer];
} else {
NSString *wrongAnswer = [[NSString alloc] initWithFormat:@"Wrong" ];
if ( [_DateField.text length] ==2 ) {
[_answerLabel setText : wrongAnswer];
}
}
- (IBAction)numbersPressed:(UIButton *)sender {
if ( [_DateField.text length] <=1) {
NSString *number = sender.currentTitle;
_DateField.text = [ _DateField.text stringByAppendingString: number];
[self checkingAnswers];
}
}