私のクイズでは、いくつかの答えがあります。正解は plist にあります。ここにあります
<array>
<dict>
<key>QuestionTitle</key>
<string>Веки являются</string>
<key>Answers</key>
<array>
<string>частью глазного яблока</string>
<string>защитным аппаратом органа зрения</string>
<string>и тем, и другим</string>
<string>ни тем, ни другим</string>
</array>
<key>CorrectAnswer</key>
<array>
<integer>0</integer>
<integer>1</integer>
</array>
</dict>
ここで、ユーザーが回答した回答を確認する方法を推測できません。A、B、C、D の回答に対して変数 0、1、2、3 を作成することはできますが、それを CorrectAnswer Array と比較する方法は m です。ファイルコード
NSString* path = [[NSBundle mainBundle] pathForResource:@"Questions2" ofType:@"plist"];
NSMutableArray *questionsDict = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSUInteger count = [questionsDict count];
for (NSUInteger i = 0; i < count; ++i)
{
int nElements = count - i;
int n = (arc4random()% nElements) + i;
[questionsDict exchangeObjectAtIndex:i withObjectAtIndex:n];
}
self.questions = [questionsDict copy];
currentQuestion = 0;
NSDictionary* nextQuestion =
[self.questions objectAtIndex: currentQuestion];//[self.questions objectForKey:
[NSString stringWithFormat:@"%d", currentQuestion]];
NSMutableArray *array = [nextQuestion[@"Answers"] mutableCopy];
self.labelA.text = [array objectAtIndex:0];
self.labelB.text = [array objectAtIndex:1];
self.labelC.text = [array objectAtIndex:2];
self.labelD.text = [array objectAtIndex:3];
self.labelQuestion.text = [nextQuestion objectForKey:@"QuestionTitle"];
//Button D (A,B,C the same)
- (IBAction)fourButton:(id)sender
{
if (chekColorD == 0)
{
chekColorD++;
[buttonD setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
//self.stringD = @"D";
}
else
{
chekColorD = 0;
[buttonD setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
// self.stringD = nil;
}
}
//NExt question button
- (IBAction)nextQuestion:(id)sender
{
// Тут делаешь сравнение правильных ответов
chekColorA = 0; chekColorB = 0; chekColorC = 0; chekColorD = 0;
[buttonA setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[buttonB setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[buttonC setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[buttonD setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
self.labelScore.text = [NSString stringWithFormat:@"%d", numCorrect];
if ([self.highScore integerForKey:@"HighScore"]<numCorrect){
[self.highScore setInteger:numCorrect forKey:@"HighScore"];
[self.highScore synchronize];
}
currentQuestion++;
if (currentQuestion <= [self.questions count]){
self.labelScore.text = [NSString stringWithFormat:@"%d", numCorrect];
self.labelHighestScore.text = [NSString stringWithFormat:@"%d",
[self.highScore integerForKey:@"HighScore"]];
NSDictionary* nextQuestion = [self.questions objectAtIndex: currentQuestion];
NSMutableArray *array = [nextQuestion[@"Answers"] mutableCopy];
self.labelA.text = [array objectAtIndex:0];
self.labelB.text = [array objectAtIndex:1];
self.labelC.text = [array objectAtIndex:2];
self.labelD.text = [array objectAtIndex:3];
self.labelQuestion.text = [nextQuestion objectForKey:@"QuestionTitle"];
//NSLog(@"%d количество вопросов", countQuestion);
}
else{
currentQuestion --;
}
}