编码阵列的前一个按钮

时间:2014-12-29 10:38:45

标签: ios objective-c arrays

我对目标C中的编程很陌生,请原谅我这个简单的问题,我即将问。我正在创建一个测验应用程序,其中一系列问题和答案都在属性列表中。我能够编写一个"下一个问题"按钮,但我不确定如何编码按钮回到上一个问题..有人可以帮忙吗??

- (void)nextQuizItem
 {
if (self.quizIndex == 999) {
    self.quizIndex = 0;
    self.statusLabel.text = @"";
} else if ((self.quiz.quizCount-1) > self.quizIndex) {
    self.quizIndex++;
} else {
    self.quizIndex = 0;
    self.statusLabel.text = @"";
}

if (self.quiz.quizCount >= self.quizIndex + 1) {
    [self.quiz nextQuestion:self.quizIndex];
    self.questionLabel.text = self.quiz.quote;
    self.answer1Label.text = self.quiz.ans1;
    self.answer2Label.text = self.quiz.ans2;
    self.answer3Label.text = self.quiz.ans3;
    self.answer4Label.text = self.quiz.ans4;
} else {
    self.quizIndex = 0;
    [self quizDone];
}


========================

  - (void) nextQuestion: (NSUInteger) idx
  {
self.quote = [NSString stringWithFormat:@"'%@'",self.movieArray[idx][@"quote"]];

self.ans1 = self.movieArray[idx][@"ans1"];
self.ans2 = self.movieArray[idx][@"ans2"];
self.ans3 = self.movieArray[idx][@"ans3"];
self.ans4 = self.movieArray[idx][@"ans4"];
self.tip = self.movieArray[idx][@"tip"];

if (idx == 0) {
    self.correctCount = 0;
    self.incorrectCount = 0;
    self.tipCount = 0;
}

1 个答案:

答案 0 :(得分:1)

- (void)prevQuizItem
 {
if (self.quizIndex == 0) {
    self.quizIndex = 999;
    self.statusLabel.text = @"";
} else if (self.quiz.quizCount > self.quizIndex-1) {
    self.quizIndex--;
} else {
    self.quizIndex = 999;
    self.statusLabel.text = @"";
}

if (self.quiz.quizCount <= self.quizIndex - 1) {
    [self.quiz prevQuestion:self.quizIndex];
    self.questionLabel.text = self.quiz.quote;
    self.answer1Label.text = self.quiz.ans1;
    self.answer2Label.text = self.quiz.ans2;
    self.answer3Label.text = self.quiz.ans3;
    self.answer4Label.text = self.quiz.ans4;
} else {
    self.quizIndex = 999;
    [self quizDone];
}