我有一个带有动物图像的数组,另一个带有相应动物声音的数组,最后一个带有动物名称的数组。例如:
图像数组:
0:[UIImage imageNamed:@"Elephant.png"]
1:[UIImage imageNamed:@"Dog.png"]
2:[UIImage imageNamed:@"Cat.png"]
声音数组:
0:大象
.mp3 1:狗.mp3
2:猫.mp3
单词数组:
0:大象
1:狗
2:猫
它们是同步的,并与同一个计数器一起工作。我想开始将它们随机排列在新的 3 个数组中,但我希望相同的动物细节(图像或声音或单词)在所有 3 个数组中都相同。例如,新数组应如下所示:
图像数组:
0:[UIImage imageNamed:@"Cat.png"]
1:[UIImage imageNamed:@"Dog.png"]
2:[UIImage imageNamed:@"Elephant.png"]
声音数组:
0:猫.mp3
1:狗.mp3
2:大象.mp3
单词数组:
0:猫
1:狗
2:大象
我将这段代码写到视图中确实加载了:
theNewAnimalsPicture = [NSArray arrayWithObjects:[UIImage imageNamed:@"Square_Bee.png"],[UIImage imageNamed:@"Square_Bird.png"],[UIImage imageNamed:@"Square_Cat.png"],[UIImage imageNamed:@"Square_Chicken.png"],[UIImage imageNamed:@"Square_Cow.png"],[UIImage imageNamed:@"Square_Dog.png"],[UIImage imageNamed:@"Square_Elephant.png"],[UIImage imageNamed:@"Square_Frog.png"],[UIImage imageNamed:@"Square_Horse.png"],[UIImage imageNamed:@"Square_Lion.png"],[UIImage imageNamed:@"Square_Monkey.png"],[UIImage imageNamed:@"Square_Sheep.png"], nil];
theNewAnimalsSound = [NSArray arrayWithObjects:@"Bee.mp3",@"Bird.mp3",@"Miao.mp3",@"Chicken.mp3",@"Cow.mp3",@"Waff.mp3",@"Elephant2.mp3",@"Frog.mp3",@"Horse.mp3",@"LionSound.mp3",@"Monkey_Sound.mp3",@"Sheep.mp3", nil];
theNewAnimalsWord = [NSArray arrayWithObjects:@"Bee",@"Bird",@"Cat",@"Chicken",@"Cow",@"Dog",@"Elephant",@"Frog",@"Horse",@"Lion",@"Monkey",@"Sheep", nil];
for (int i =0;i<[theNewAnimalsPicture count];i++)
{
int number = arc4random() % [theNewAnimalsPicture count];
[PicturesAnimalArray addObject:[theNewAnimalsPicture objectAtIndex:number]];
[SoundsAnimalArray addObject:[theNewAnimalsSound objectAtIndex:number]];
[wordAnimalArray addObject:[theNewAnimalsWord objectAtIndex:number]];
[theNewAnimalsPicture removeObjectAtIndex:number];
[theNewAnimalsSound removeObjectAtIndex:number];
[theNewAnimalsWord removeObjectAtIndex:number];
}
它不工作。为什么会这样,我怎样才能以比我在这里做的更有效的方式做到这一点?