Pick unique image from array problem
Hi, i have 50 images, when the user press a button (i need help with the following) - 1.create an array of the filenames (imageBall1, imageBall2 ...). 2.pick one random image. 3.pass the selected image to the object ball in this code (ball1 is a UIImageView):
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5]; CGPoint destination = CGPointMake(100,100); ball1.center = destination; [UIView commitAnimations];
4.repeat this process 6 times but each time pick a unique image (that didn't get picked in this event) and do it each time for a different object (ball1, ball2... ball6).
i have the following code that possibly help:
//create an array of filenames
NSMutableArray *imageArray;
for (int c=0;c<2;c++)
{
NSString *imageName = [NSString stringWithFormat:@"name%d.png", c];
[imageArray addObject: imageName];
}
//pick one filename
int numFileNames = [imageArray count];
int chosen = arc4random() % numFileNames;
NSString *oneFilename = [imageArray objectAtIndex: chosen];
thanks!!
|