您的位置:首页 > 产品设计 > 产品经理

iphone development NSBundle pathForResource load images from subfolder problem

2010-12-31 17:03 459 查看
+ (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext inDirectory:(NSString *)bundlePath;

- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext;

- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext inDirectory:(NSString *)subpath;



I was fucked by this method today, some guy said it's a bug, eventually I found it's not a bug.



We see Resources/Images folder in project panel in XCode, yes we do see it existing, but if you open your project folder on your hardware, you'll see neither "Resources" folder nor "Images" folder, and the images are exhibited in root

folder of your project, that's why the following is wrong:



NSString *resource = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"png" inDirectory: @"images"];



instead if you have this folder “images" in your hardware, you could use above method. otherwise let's

use below one:



NSString *resource = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"png" inDirectory: @""];

or

NSString *resource = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"png"];



The REASON is the "Resources" and "images" folder is just a "SOFT" group structure we saw in XCode, they are not mapping to real folder on hardware, so the compiled app doesn't include this "SOFT" folder structure, then you can't find that file in subfolder.



原因就是我们看到的文件夹结构并不是实际的硬盘上的文件夹结构,所以编译完成的iphone应用程序的bundle里没有这个组织结构。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: