对此有一些困难。 我正在从一个plist上加载问题,答案和正确的答案。所有数据都被正确读取,如下所示
- (void)viewDidLoad
{
[super viewDidLoad];
rootArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"question" ofType:@"plist"]];
currentQuestion = -1;
[self showNextQuestion];
}
-(void) showNextQuestion{
currentQuestion++;
int numItems = [rootArray count];
NSMutableArray *question = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *A = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *B = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *C = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *addimage = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *Answer = [NSMutableArray arrayWithCapacity:numItems];
for (NSDictionary *itemData in rootArray) {
[question addObject:[itemData objectForKey:@"question"]];
[A addObject:[itemData objectForKey:@"A"]];
[B addObject:[itemData objectForKey:@"B"]];
[C addObject:[itemData objectForKey:@"C"]];
[addimage addObject:[itemData objectForKey:@"ImageUse"]];
[Answer addObject:[itemData objectForKey:@"ANS"]];
}
self.questionasked.text = question[currentQuestion];
self.answer1.text = A[currentQuestion];
self.answer2.text = B[currentQuestion];
self.answer3.text = C[currentQuestion];
additionImage.image = [UIImage imageNamed:addimage[currentQuestion]];
self.correctAns = Answer[currentQuestion];
if(currentQuestion == 4){
[ self performSegueWithIdentifier:@"levelclear" sender:nil];// here I am performing a segue to indicate that when 4 questions are displayed it will go to this view controller
}
}
我的VC中有3个按钮,每个选项A,B,C都有一个功能
- (IBAction)SelectA:(id)sender {
if ([self.correctAns isEqualToString:@"A"]) {
currentQuestion ++;
[self showNextQuestion];
}
else{
[self performSegueWithIdentifier:@"incorrect" sender:nil];
}
}
- (IBAction)SelectB:(id)sender {
if ([self.correctAns isEqualToString:@"B"]) {
currentQuestion ++;
[self showNextQuestion];
}
else{
[self performSegueWithIdentifier:@"incorrect" sender:nil];
}
}
- (IBAction)SelectC:(id)sender {
if ([self.correctAns isEqualToString:@"C"]) {
currentQuestion ++;
[self showNextQuestion];
}
else{
[self performSegueWithIdentifier:@"incorrect" sender:nil];
}
}
当我正确回答问题时,它转到下一个问题。但是,当我错误地回答它时,它会转到错误的VC,通知错误的问题。当按下按钮返回问题VC(我在故事板中制作)时,此VC有一个segue。它确实回到了VC的问题,但只是跳回到第一个问题。我知道这是关于当前问题的,但不确定是什么。
答案 0 :(得分:0)
看起来当你错误地回答你正在摧毁问题视图控制器时,当你回到它时,它会重新创建。