Quote:
Originally Posted by smasher
That's not a great way to store you data; as you've seen already it makes it hard to do operations at the question level. You'd be better off with a "Question" object that has properties for the question, answer1, answer2, answer3, and correct. Then you can shuffle an array of those objects with the method above.
If you really don't want a custom object (even though you really do, trust me) then you could make an array of five arrays - The master array will have five items, each of those items will be an array representing a single question / answer set. Like so:
Code:
NSArray *quizArray = [[NSArray alloc] initWithObjects:
[NSArray arrayWithObjects: @"Question number one? (correct A) ",@"A",@"B",@"C",@"D",@"1", nil],
[NSArray arrayWithObjects: @"Question number two? (correct B) ",@"A",@"B",@"C",@"D",@"2", nil],
[NSArray arrayWithObjects: @"Question number three? (correct C) ",@"A",@"B",@"C",@"D",@"3", nil],
[NSArray arrayWithObjects: @"Question number four? (correct D) ",@"A",@"B",@"C",@"D",@"4", nil],
[NSArray arrayWithObjects: @"Question number five? (correct A) ",@"A",@"B",@"C",@"D",@"1", nil],
nil];
You get the idea? Now you can shuffle quizArray using the code above without losing the connection between questions and answers.
|
ok, im trying to explain my problem in details. i have to use this method, because i have written a lot of codes, where from my array get the right answer the question and the four answers. ill describe how it is done:
example my array is like this:
"
NSArray *quizArray = [[NSArray alloc] initWithObjects:
@"Question number one? (correct A) ",@"A",@"B",@"C",@"D",@"1",
@"Question number two? (correct B) ",@"A",@"B",@"C",@"D",@"2",
@"Question number three? (correct C) ",@"A",@"B",@"C",@"D",@"3",
@"Question number four? (correct D) ",@"A",@"B",@"C",@"D",@"4",
@"Question number five? (correct A) ",@"A",@"B",@"C",@"D",@"1",
nil];
self.theQuiz = quizArray;
[quizArray release];
"
and im describing how the objects are sorted: example
@"Question number one? (correct A) ",@"A",@"B",@"C",@"D",@"1",
@"Question number one? (correct A) ",@" - this is the question(the index for this is 0

@"A",@"B",@"C",@"D, - those are choices (the index for this is 1,2,3,4

",@"1", - this is the right answer (it could be 1,2,3,4 variuosly from the right answer)
so this is simple done, but i want this array to shuffle resort.
Is this way possible to be done or i MUST change my way of doing quizarray?