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里没有这个组织结构。
- (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里没有这个组织结构。
相关文章推荐
- 关于[[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"]找不到指定文件的解决办法
- NSBundle pathForResource取不到值
- [NSBundle mainBundle] pathForResource: ofType: 获取不到数据
- iOS开发 [NSBundle mainBundle] 通过pathForResource返回路径为空.
- NSBundle pathForResource is NULL 取不到值
- 关于[[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"]找不到指定文件的解决办法
- NSBundle pathForResource取不到值如何解决?
- NSBundle pathForResource取不到值
- [[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"] 找不到对应的文件解决方法
- NSBundle pathForResource取不到值问题
- NSBundle pathForResource取不到值如何解决?
- [[NSBundle mainBundle]pathForResource:@"name" ofType:@"type"] 获取不到本地文件
- NSBundle pathForResource取不到值问题
- [NSBundle mainBundle] pathForResource: ofType: 获取不到数据
- 关于[[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"]找不到指定文件的解决办法
- Xcode resource groups and folder references when building for iPhone
- iOS开发中 [[NSBundle mainBundle] pathForResource: ofType:]路径为空的问题
- Tensorflow Image Processing Basic 2: Load Images from folder
- iOS [[NSBundle mainBundle] pathForResource:@"" ofType:@""]无法获取到文件
- NSBundle的pathForResource:ofType: 返回值为nil问题