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