NSBundle的使用,注意mainBundle和Custom Bundle的区别
1、[NSBundle mainBundle],文件夹其实是Group,如左侧的树形文件管理器

Build之后,文件直接就复制到了根目录下,于是读取的方法,应该是这样:
NSString *earth = [[NSBundle mainBundle] pathForResource:@"Brad Cox" ofType:@"png"]; |
2、使用文件夹的时候,Build结果

依然使用同样的方法,不需要制定文件夹路径
//inDirectory参数可有可无
NSString *earth = [[NSBundle mainBundle] pathForResource:@"Matthijs" ofType:@"png" inDirectory:@"Images/MoreImages"];
NSString *earth = [[NSBundle mainBundle] pathForResource:@"Matthijs" ofType:@"png"];
编译之后,mainBundle的资源都是放到RootFolder下,所以,可以直接访问,不要指定内部路径
3、使用其他的Bundle

NSString *resourceBundle = [[NSBundle mainBundle] pathForResource:@"Resources" ofType:@"bundle"]; NSLog(@"resourceBundle: %@", resourceBundle); NSString *earth = [[NSBundlebundleWithPath:resourceBundle] pathForResource:@"Matthijs"ofType:@"jpg"inDirectory:@"Images/MoreImages"]; NSLog(@"path: %@", earth); |
使用Custom bundle,访问内部的子文件夹,需要指定inDirectory参数,这个mainBundle不同,这是为何?
注意:Sincebundles other than the main bundle can have folders embedded inside them, to accessfiles inside folders of a bundle other than the main bundle it is best to use the pathForResource:ofType:inDirectory: method of NSBundle to explicitly specify the folder inwhich a specific file/resource exists. |
NSBundle的使用,注意mainBundle和Custom Bundle的区别的更多相关文章
- IOS NSBundle的使用,注意mainBundle和Custom Bundle的区别
1.[NSBundle mainBundle],文件夹其实是Group,如左侧的树形文件管理器 Build之后,文件直接就复制到了根目录下,于是读取的方法,应该是这样: NSString *earth ...
- 【转】NSBundle的使用,注意mainBundle和Custom Bundle的区别
1.[NSBundle mainBundle],文件夹其实是Group,如左侧的树形文件管理器 Build之后,文件直接就复制到了根目录下,于是读取的方法,应该是这样: NSString *earth ...
- webpack中的 chunk,module,bundle的区别,以及hidden modules是什么
hidden modules是什么: chunk,module,bundle的区别 总结: module是指任意的文件模块,等价于commonjs中的模块 chunks是webpack处理过程中被分组 ...
- IOS NSBundle 的理解和 mainBundle 类方法详解
常看到类似的 NSString *file = [[NSBundle mainBundle] pathForResource:name ofType:nil]; 这样的代码,用来获取 file 的完全 ...
- NSBundle的理解和mainBundle的基本介绍
一.NSBundle NSBundle是cocoa为bundle提供的一个类,bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像.声音.编译好的代码.nib文件.(用户也会把 ...
- NSBundle 的理解和 mainBundle
http://www.360doc.com/content/15/0629/10/20918780_481405304.shtml
- Unity中 动态加载 Resources.Load()和Asset Bundle 的区别
版权声明:本文为博主原创文章,未经博主允许不得转载. 初学Unity的过程中,会发现打包发布程序后,unity会自动将场景需要引用到的资源打包到安装包里,没有到的不会跟进去.我们在编辑器里看到的Ass ...
- WinForm中Component Class、User Control及Custom Control的区别和使用建议
reference: http://blog.csdn.net/redstonehe/article/details/1536549 .NET Framework 为您提供了开发和实现新控件的能力.除 ...
- WinForm中Component Class、User Control及Custom Control的区别和使用-转
转http://www.cnblogs.com/jhtchina/archive/2010/11/28/1028591.html NET Framework 为您提供了开发和实现新控件的能力.除了常见 ...
随机推荐
- CentOS 7 gedit编辑器中文乱码解决方法
无需root登陆 打开终端输入如下命令: gsettings set org.gnome.gedit.preferences.encodings auto-detected "['GB180 ...
- 揭开CSS3媒体查询迷雾(min-width和max-width)
本文参考MichelleKlann的Media Queries Demystified: Min-Width and Max-Width 媒体查询(media queries)是响应式设计(Respo ...
- listview使用checkbox批量删除出现的问题
1.选中前面的checkbox导致后的checkbox被选中 2.选中后下滑listview,再上滑时被选中的checkbox又变成未选中状态. 问题大都是因为对listview进行代码优化重用con ...
- C# String 前面不足位数补零的方法 PadLeft
PadLeft(int totalWidth, char paddingChar) //在字符串左边用 paddingChar 补足 totalWidth 长度PadLeft(int totalWid ...
- php正则贪婪匹配与非贪婪匹配一些例子
http://www.111cn.net/phper/210/55600.htm 贪婪模式匹配的原则是: 在可匹配也可不匹配的情况下, 优先匹配,直到不能匹配成功的情况下,记录备选状态,并把匹配控制交 ...
- Server Error The server encountered an error and could not complete your request. 新建站点模版失败
500 Server Error Error: Server Error The server encountered an error and could not complete your req ...
- Java教程——int与Integer的区别
首先说一下int和Integer的区别: int 是基本数据类型,Integer是int的包装类.注意:后者的类型是"类".例如使用泛型,List<Integer> n ...
- 10_Jaxws使用自定义pojo发布服务
[简述] 查询三天的天气信息(天气概况.日期.温度),测试jaxws是否支持自定义pojo发布服务. [开发过程] 服务端: 1.自定义pojo(天气概况.日期.温度) 2.开发SEI接口及实现类 3 ...
- hdu 5009 Paint Pearls
首先把具有相同颜色的点缩成一个点,即数据离散化. 然后使用dp[i]表示涂满前i个点的最小代价.对于第i+1个点,有两种情况: 1)自己单独涂,即dp[i+1] = dp[i] + 1 2)从第k个节 ...
- https证书申请
因为要为海外组的aws设置https证书,由于使用的是新的域名,所以要先申请购买证书,然后设置上去.由于是第一次做这件事.所以过程有些坎坷. 先购买https证书.看了几家,感觉GoDad ...