I’m new to Objetive-C and need some help,
I have an Array with 22 UIImage’s and 4 UIButtons on the view.
I want to take an image from the array with ObjectAtIndex:somecounter and place this image randomly in one of the 4 UIButton’s, than I want to take another 3 UIImages from the Array (random images) and locate them randomly in the other 3 UIButtons that I have left.
so in each time that the counter is in a number, take the UIImage that stored in this index, locate it randomly in one of the UIButtons, than take other 3 random UIImages from the Array and locate them randomly on the 3 UIButton that I have left.
how can I do that?
after using basvk answer came up with this:
-(void)PlaceWordAndPictueOnScreen
{
NSArray *buttons = [NSArray arrayWithObjects:btnLetter1, btnLetter2, btnLetter3, btnLetter4, nil];
for (UIButton *btn in buttons) {
int randomIndex= random() % [LettersArray count];
UIImage *img = [LettersArray objectAtIndex:randomIndex];
[btn setImage:img forState:UIControlStateNormal];
[LettersArray removeObjectAtIndex:randomIndex];
}
}
so I did exactly as he said and it worked like charm, but, I do have a problem.
I have this counter called ‘imgcounter’, lets say he’s value is ‘4’, I want to take the image that located at index 4 and put it in one of the ‘btnLetter’ UIButton, but in a random button, than in the other 3 ‘btnLetter’ buttons that left, to put another 3 random UIImage’s, how can I do that?
Thanks..
Out the top of my head, something like this: