JustAnotherCoder
JustAnotherCoder

Reputation: 2575

Help with Multiple Choice App?

I'm still quite new at iPhone/Xcode development. I made one app so far that got published on the app store but it was a simple game. So please bear with me.

Now I am trying to create an app that will basically be like a multiple choice test. I was thinking it would go like this:

  1. Show question 1 and choices 1
  2. user picks answer
  3. check if user's answer is same as question 1 answer
  4. show question 2 and choices 2 etc.

What is usually the best way to do this? Do I create an array that has the "question, choices and answer key" in each slot then load them onto the screen one by one? Is that even possible? Can I have three values in a single array slot?

Thanks for your help. Any input would be appreciated.

Upvotes: 0

Views: 1930

Answers (2)

alloc_iNit
alloc_iNit

Reputation: 5183

You should use a NSMutableArray filled with separate NSDictionaries contains bunch of question and its answer. Each new question and answer is to be stored into the NSDictionary and that NSDictionary will going to add into the NSMutableArray. According to the next level of game, you can have get the new question and answer in memory in form of NSDictionary from the index of NSMutableArray.

i.e.

    NSMutableArray *arBook = [[NSMutableArray alloc] init];
    NSDictionary *dic1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"Who is CEO of apple?", @"Question", @"Steve Jobs", @"Answer"];
    [arBook addObject:dic1]; 

So on you may add all questions along with answers.

Is it clear to you?

Upvotes: 1

john
john

Reputation: 3103

NSDictionary would be good for this. You can make the key be the question, and its value be the choices. Then you could have a second NSDictionary which would have the key be the question, and its value be the answer. Comparing values this way would be easy.

NSDictionary *questions = [[NSDictionary alloc] initWithObjectsAndKeys: firstQuestion, firstChoices, secondQuestion, secondChoices, nil];
NSDictionary *answers = [[NSDictionary alloc] initWithObjectsAndKeys: firstQuestion, firstAnswer, secondQuestion, secondAnswers, nil];

Where firstQuestion, firstChoices, firstAnswer, etc. would be objects you create and store in the dictionary, I'd recommend NSStrings.

Or, you could always create your own custom objects to handle all this.

Upvotes: 1

Related Questions