好的,所以我正在研究这个应用程序,我遇到了一个问题......到目前为止,设置就是这个。我有16个按钮设置为图像。我对所有这些按钮设置了arc4random()%16,这样所有按钮都有可能成为16个图像中的一个。我为每种图片类型设置了一个switch语句,每个case都有一个不同的图像。现在,我想要的是所有图像一次使用...当应用程序运行时没有重复,我只是想以随机顺序。有什么方法可以做到吗?目前,当我运行应用程序时,一些图像不止一次出现,因为每个按钮可以是16个图像中的一个。我只想让图像出现一次。我不知道该怎么做,也许在每个案例中添加16 if / if else语句???请帮忙!!! 这是我当前第一个switch语句的语法。谢谢!
-(void)Picture1SelectedType{
switch (Picture1Type) {
case 0:
{
UIImage *pictureImage = [UIImage imageNamed: @"Plastic-Brick-Man@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
case 1:
{
UIImage *pictureImage = [UIImage imageNamed: @"Games-Console---1@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
case 2:
{
UIImage *pictureImage = [UIImage imageNamed: @"Old-Telephone@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
case 3:
{
UIImage *pictureImage = [UIImage imageNamed: @"Scarf@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
case 4:
{
UIImage *pictureImage = [UIImage imageNamed: @"Camera@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
case 5:
{
UIImage *pictureImage = [UIImage imageNamed: @"Tea-Cup@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
case 6:
{
UIImage *pictureImage = [UIImage imageNamed: @"Fruit-Computer---3@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
case 7:
{
UIImage *pictureImage = [UIImage imageNamed: @"Sugary-Drink@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
case 8:
{
UIImage *pictureImage = [UIImage imageNamed: @"Fruit-Computer@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
case 9:
{
UIImage *pictureImage = [UIImage imageNamed: @"Pocket-Watch@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
case 10:
{
UIImage *pictureImage = [UIImage imageNamed: @"Starship@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
case 11:
{
UIImage *pictureImage = [UIImage imageNamed: @"Games-Controller---1@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
case 12:
{
UIImage *pictureImage = [UIImage imageNamed: @"Two-tone-Shoe@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
case 13:
{
UIImage *pictureImage = [UIImage imageNamed: @"Lightbulb@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
case 14:
{
UIImage *pictureImage = [UIImage imageNamed: @"Bike@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
case 15:
{
UIImage *pictureImage = [UIImage imageNamed: @"Flower-Vase@Low.png"];
[Picture1 setImage:pictureImage forState:UIControlStateNormal];
[self.view addSubview:Picture1];
}
break;
default:
break;
}