Quote:
Originally Posted by Duncan C
Huh? "takes twice the same object?" What does that mean?
You mean that more than one label could get the same text? That's true. The OP did not say that he wanted the random text to be random, non-repeating text. That would require a bit more code.
I have a post linked in my signature that shows how to generate random, non-repeating strings. That code could be easily adapted to create random, non-repeating button labels.
|
I got it to work.
I have these in the'.h' file
int count
NSArray *gamewords
//this is what worked in the '.m' file
NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"Words" ofType:@"plist"];
NSMutableDictionary *plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:dataPath];
gameWords = [plistDict objectForKey:@"gameWords"];
// initial load of words onto labels randomly
count = [gameWords count];
label1.text = [gameWords objectAtIndex:arc4random() % count];
label2.text = [gameWords objectAtIndex:arc4random() % count];
label3.text = [gameWords objectAtIndex:arc4random() % count];
label4.text = [gameWords objectAtIndex:arc4random() % count];
label5.text = [gameWords objectAtIndex:arc4random() % count];
label6.text = [gameWords objectAtIndex:arc4random() % count];
label7.text = [gameWords objectAtIndex:arc4random() % count];
Thanks so much for all your help
Tom