0

我创建了一个有 4 个答案的测验,其中一个是正确答案。我保留在 plist 中的问题和答案。(其中有字典数组)。现在我想对一个问题有不止一个正确答案。示例:用户可以选择 ABCD 或 AC 或 BCD 等,然后按下“下一个问题”按钮。请告诉我实现使命的正确方法!

对不起我的ENG,我是俄罗斯人。

m.文件

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
4

1 回答 1

0

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

在此处输入图像描述

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

于 2013-08-31T11:20:23.693 回答