我用4個答案創建了一個測驗,其中一個答案是正確答案。問題和答案我保持plist。(它有字典數組)。 現在我想對一個問題有多個正確的答案。例如:用戶可以選擇A B C D或A C或B C D等,然後按下「下一個問題」按鈕。 請告訴我實現我的使命的正確方法!如何在測驗中實現幾個答案?
對不起,我是ENG,我是俄羅斯人。
m.file
enter code here- (void)showNextQuestion
{
if ([self.highScore integerForKey:@"HighScore"]<numCorrect){
[self.highScore setInteger:numCorrect forKey:@"HighScore"];
[self.highScore synchronize];
}
currentQuestion++; //= arc4random()%10;
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];//[self.questions objectForKey:[NSString stringWithFormat:@"%d", currentQuestion]];
NSString* correctAnswer = [nextQuestion objectForKey:@"CorrectAnswer"];
self.answer = correctAnswer;
self.labelA.text = [nextQuestion objectForKey:@"A"];
self.labelB.text = [nextQuestion objectForKey:@"B"];
self.labelC.text = [nextQuestion objectForKey:@"C"];
self.labelD.text = [nextQuestion objectForKey:@"D"];
self.labelQuestion.text = [nextQuestion objectForKey:@"QuestionTitle"];
NSLog(@"%d количество вопросов", countQuestion);
int questNumber = countQuestion+1;
NSString *questNumberString = [[NSString alloc] initWithFormat:@"%d", questNumber];
NSLog(@"%@", questNumberString);
questNum.text = questNumberString;
- (IBAction)buttonPressedA:(id)sender {
//AudioServicesPlaySystemSound(SoundID1);
countQuestion++;
if([self.answer isEqualToString: @"A" ]){
numCorrect += 1;
self.labelScore.text = [NSString stringWithFormat:@"%d", numCorrect];
}
[self showNextQuestion];
}
- (IBAction)buttonPressedB:(id)sender {
// AudioServicesPlaySystemSound(SoundID1);
countQuestion++;
if([self.answer isEqualToString: @"B"]){
numCorrect += 1;
self.labelScore.text = [NSString stringWithFormat:@"%d", numCorrect];
}
[self showNextQuestion];}
- (IBAction)buttonPressedC:(id)sender {
//AudioServicesPlaySystemSound(SoundID1);
countQuestion++;
if([self.answer isEqualToString: @"C"]){
numCorrect += 1;
self.labelScore.text = [NSString stringWithFormat:@"%d", numCorrect];
}
[self showNextQuestion];}
- (IBAction)buttonPressedD:(id)sender {
//AudioServicesPlaySystemSound(SoundID1);
countQuestion++;
if([self.answer isEqualToString: @"D"]){
numCorrect += 1;
self.labelScore.text = [NSString stringWithFormat:@"%d", numCorrect];
}
[self showNextQuestion];}
@end
顯示您的單一選擇答案的代碼。你怎麼知道哪個問題有多個答案? – Wain