1
我想将文件的内容传递到一个数组,然后由随机图像生成器调用。我错过了一些东西(或很多东西)。有任何想法吗?在随机生成器中使用NSMutableArray
NSString *chords = [[NSBundle mainBundle] pathForResource:@"ChordCharts" ofType:nil];
chordCharts = [NSMutableArray arrayWithContentsOfFile:chords];
int randomimages = rand() % 4;
switch (randomimages) {
case 0:
chordImage.image = [UIImage imageNamed:[chordCharts objectAtIndex:0]];
break;
case 1:
chordImage.image = [UIImage imageNamed:[chordCharts objectAtIndex:1]];
break;
case 2:
chordImage.image = [UIImage imageNamed:[chordCharts objectAtIndex:2]];
break;
case 3:
chordImage.image = [UIImage imageNamed:[chordCharts objectAtIndex:3]];
break;
default:
break;
}
阿(开头和结尾删除空格),没赶上的plist的事。我将重新编写代码。真正的问题是,调用此方法时不会显示图像。我希望能找到一种有效的方法来将大量的.png文件存储在一个数组中,然后在开关盒中调用这些地址。这样,我不必写出如此多的UIImage名称。那有意义吗? – 2012-07-14 20:26:20