當你這樣做 - [bgImages objectAtIndex:currentBackground]
- 你得到一個UIImage
的實例。當你做你的stringWithFormat
,你是對的,它只是打印圖像的地址,沒有更多。
不幸的是有沒有辦法讓「名」的圖像背出UIImage
實例,所以你可能會不得不做這樣的事情:
currentBackground=4;
bgImages = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"mystery_01 320x460"],
[UIImage imageNamed:@"mystery_02 320x460"],
[UIImage imageNamed:@"mystery_03 320x460"],
[UIImage imageNamed:@"mystery_04 320x460"],
[UIImage imageNamed:@"mystery_05 320x460"],
nil];
bgImageNames = [[NSArray alloc] initWithObjects:
@"mystery_01 320x460",
@"mystery_02 320x460",
@"mystery_03 320x460",
@"mystery_04 320x460",
@"mystery_05 320x460",
nil];
然後執行:
mainLabel.text = [NSString stringWithFormat:@"bgImages= %@",[bgImageNames objectAtIndex:currentBackground]];
或者包裹bgImages
排列了一下的創建,你甚至可以聰明,這樣做:
currentBackground=4;
bgImageNames = [[NSArray alloc] initWithObjects:
@"mystery_01 320x460",
@"mystery_02 320x460",
@"mystery_03 320x460",
@"mystery_04 320x460",
@"mystery_05 320x460",
nil];
NSMutableArray *newBgImages = [NSMutableArray arrayWithCapacity:0];
for (NSString *image in bgImageNames) {
[newBgImages addObject:[UIImage imageNamed:image]];
}
bgImages = [NSArray arrayWithArray:newBgImages];
您使用的是什麼技術?適當地重新標記將有助於將問題提供給正確的受衆,並得出更好的答案。 – 2012-02-06 18:10:48