In my FirstViewcontroller
I have picker containing 1
to 25
values, if the user select 5 in the picker on the next screen it should display 5 images randomly out of 25 images without repetition of that 5 images. If user selects another number means it takes that number as input and it should display images according to that number. If I run my code means every time it showing all 25 images not selected number images. Here is my code
- (void)viewDidLoad {
myImageNames = [[NSMutableArray alloc] init];
[myImageNames addObject:[UIImage imageNamed:@"Red.png"]];
[myImageNames addObject:[UIImage imageNamed:@"Blue.png"]];
[myImageNames addObject:[UIImage imageNamed:@"LightRed.png"]];
[myImageNames addObject:[UIImage imageNamed:@"Orange.png"]];
.
.
.
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(ChangingImgView:) userInfo:nil repeats:YES];
}
- (void) ChangingImgView:(int)selectedNumberFromPicker {
selectedNumberFromPicker = [num intValue];
for (int i=0; i < selectedNumberFromPicker; i++) {
index = arc4random() % 25;
NSString *strIndex = [NSString stringWithFormat:@"%i",index];
[myImageNames addObject:strIndex];
imgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
imgBtn.frame = CGRectMake(250, 300, 170, 220);
UIImage *img = [myImageNames objectAtIndex:index];
[imgBtn setBackgroundImage:img forState:UIControlStateNormal];
[imgBtn addTarget:self action:@selector(ClickingOnImage) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:imgBtn];
}
}
Please help me.