当你这样做 - [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