我的文件名爲:landing_load1 @ 2x ... landing_load4 @ 2x在我的項目中。 (沒有非視網膜文件)NSBundle mainBundle pathForResource:不工作,除非@ 2x包括
此代碼:
for(int x=1; x < 5; x++){
NSString * imageTitle = [NSString stringWithFormat:@"landing_load%[email protected]", x];
UIImage * loadingImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageTitle ofType:@"png"]];
[loadingImages addObject:loadingImage];
}
但是,這並不工作:
for(int x=1; x < 5; x++){
NSString * imageTitle = [NSString stringWithFormat:@"landing_load%i", x];
UIImage * loadingImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageTitle ofType:nil]];
[loadingImages addObject:loadingImage];
}
而且這不起作用:
for(int x=1; x < 5; x++){
NSString * imageTitle = [NSString stringWithFormat:@"landing_load%i", x];
UIImage * loadingImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageTitle ofType:nil]];
[loadingImages addObject:loadingImage];
}
問題:我知道我不必顯式調用@ 2x或指定文件類型,所以任何想法爲什麼它不工作,除非我明確寫出整個fi列出來?
注:測試的iPad 4
更新了問題。除非添加@ 2x,否則仍然不起作用。謝謝 – user3456115