2013-08-31 31 views
0

我用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 
+2

顯示您的單一選擇答案的代碼。你怎麼知道哪個問題有多個答案? – Wain

回答

0

裏面你的plist,使答案本身的字典。標題使用一個鍵/值對,另一個用於指示它是否正確。

enter image description here

當用戶選擇一個答案,你只需要檢查相應的布爾值(在這種情況下,「正確」)。

+0

請,你能寫出更詳細的答案或者給一個有用的鏈接,謝謝! –

+0

你不明白什麼部分? –

+0

我有項目0,1,2 ...在女巫我有鑰匙「QuestionTitle」,「A」「B」「C」「D」,「CorrectAnswer」它的所有類型的字符串。我應該改變「CorectAnswer」到類型字典? –