i managed to read my question from my question.plist for question and answer.
self.view.backgroundColor = [UIColor colorWithRed:99.0/255.0 green:162.0/255.0 blue:223.0/255.0 alpha:1.0];
self.title = @"Game"; //Set title.
// Path to the plist (in the application bundle)
NSString *path = [[NSBundle mainBundle] pathForResource:
@"Question" ofType:@"plist"];
NSArray *array = [NSArray arrayWithContentsOfFile:path];
NSDictionary *dict = [array objectAtIndex:0];
questionlabel.text = [dict valueForKey:@"Question"];
a button here to call for QR code scanner, after scanning it will check if the answer is correct or wrong and direct the user to another question in the question.plist(objectAtIndex:1) if is correct if not it will pop up and show is incorrect
i can do it in a static way of creating a few more to xib to create other question statically, however i know this is a troublesome way to do it. anybody know how can i do it in a dynamic way?
thanks in advances
Desmond
What does the QR code scanner have to do with anything? I think it is not strictly relevant to your question, so I’ll only cover exactly what you’re asking. QR code scanning is not a part of the iOS and is provided by external libraries.
Add an integer i-var to the view controller:
Then, when loading the question and updating the UI, use that i-var to construct the NSString from which you’ll load the question.
Alternatively, consider storing all questions in a single plist whose root is an array. Then use
NSArray‘s-objectAtIndex:method to grab the current question (simply passcurrentQuestionas the first argument).In any case, the place where you check for answer correctness (in a quiz) or where you record the answer (in a questionnaire) will need to update the current question and update UI:
Updating UI reads the next question and updates labels and buttons appropriately.