i have quiz app for the iPhone, i’m able to load random question from plist file and i want to ask about 20 questions; in my plist file i have 20 more, but i don’t want that in one quiz session one question is repeated.
this is my plist file `
<key>Domanda1</key>
<dict>
<key>immagine</key>
<string>hpv</string>
<key>Titolo</key>
<string>Domanda numero 1</string>
<key>Risposta1</key>
<string>Risposta primaD1</string>
<key>Risposta2</key>
<string>Risposta seconda</string>
<key>Risposta3</key>
<string>Risposta terza</string>
<key>Risposta4</key>
<string>Risposta quarta</string>
<key>Soluzione</key>
<integer>1</integer>
</dict>
<key>Domanda2</key>
…….
`
my view controller.m
-(void)creaDomanda {
//scelta casuale tra le varie disponibili
int randomValue = (arc4random() % 20) + 1;
NSString *stringa = [NSString stringWithFormat:@"Domanda%i", randomValue];
// Apre il dictionary
dictionary = [plistData objectForKey:stringa];
// e stampa a schermo la domanda
label1.text = [dictionary valueForKey:@"Titolo"];
label1.textColor = [UIColor redColor];
………
Any ideas?
thank’s in advance
Create a mutable array and copy your questions into it in numerical order. Select questions from the array using a random value. When you ask a question, remove it from the array. To generate a new random value, use the number of items still in the array instead of “20”.