+ (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里没有这个组织结构。