I choose index of an array from a plist. It's a dictionary with 10 different line with string.
NSArray* tableau = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"codes" ofType:@"plist"]];
NSDictionary* phrase = [tableau objectAtIndex:nombreChoisi];
I would like to take 6 elements and put them in 6 labels randomly
I tried this to pass it in a new NSMutableArray, but it doesn't work:
NSArray* tableau = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"codes" ofType:@"plist"]];
NSDictionary* phrase = [tableau objectAtIndex:nombreChoisi];
NSString *phraseMelange1 = [phrase objectForKey:@"texte1"] ;
NSString *phraseMelange2 = [phrase objectForKey:@"texte2"] ;
NSString *phraseMelange3 = [phrase objectForKey:@"texte3"] ;
NSString *phraseMelange4 = [phrase objectForKey:@"texte4"] ;
NSString *phraseMelange5 = [phrase objectForKey:@"texte5"] ;
NSString *phraseMelange6 = [phrase objectForKey:@"texte6"] ;
NSMutableArray *tableauMelange = [[NSMutableArray alloc] initWithObjects:
phraseMelange1,
phraseMelange2,
phraseMelange3,
phraseMelange4,
phraseMelange5,
phraseMelange6,
nil];
for(int i=0;i<6;i++)
{
int idx;
idx = random()%[tableauMelange count];
NSString* titre = [tableauMelange objectAtIndex:idx];
texte1.text = titre;
[tableauMelange removeObjectAtIndex:idx];
}
{
int idx;
idx = random()%[tableauMelange count];
NSString* titre = [tableauMelange objectAtIndex:idx];
texte2.text = titre;
[tableauMelange removeObjectAtIndex:idx];
}
{
int idx;
idx = random()%[tableauMelange count];
NSString* titre = [tableauMelange objectAtIndex:idx];
texte3.text = titre;
[tableauMelange removeObjectAtIndex:idx];
}
{
int idx;
idx = random()%[tableauMelange count];
NSString* titre = [tableauMelange objectAtIndex:idx];
texte4.text = titre;
[tableauMelange removeObjectAtIndex:idx];
}
{
int idx;
idx = random()%[tableauMelange count];
NSString* titre = [tableauMelange objectAtIndex:idx];
texte5.text = titre;
[tableauMelange removeObjectAtIndex:idx];
}
{
int idx;
idx = random()%[tableauMelange count];
NSString* titre = [tableauMelange objectAtIndex:idx];
texte6.text = titre;
[tableauMelange removeObjectAtIndex:idx];
}
[tableauMelange release];
I also try this with :
NSMutableArray *array;
array=[[phrase allKeys] mutableCopy];
But It gives me the keys and not the value without possibility to choose those I need.
Thanks for your help.