如何在测验中实现几个答案?

时间:2013-08-31 10:59:44

标签: ios testing plist

我创建了一个有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

1 个答案:

答案 0 :(得分:0)

在你的plist里面,把答案本身变成一本字典。使用一个键/值对作为标题,另一个用于指示它是否正确。

enter image description here

当用户选择答案时,您只需检查相应的布尔值(在本例中为“正确”)。