在我的选择器中FirstViewcontroller
包含值,如果用户在下一个屏幕的选择器中选择 5,它应该从 25 个图像中随机显示 5 个图像,而不重复这 5 个图像。如果用户选择另一个数字意味着它将该数字作为输入,它应该根据该数字显示图像。如果我运行我的代码意味着每次它显示所有 25 张图像而不是选定的数字图像。这是我的代码1
25
- (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];
}
}
请帮我。