IOS 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不同,这是为何?
注意:Since
bundles other than the main bundle can have folders embedded inside them, to access
files inside folders of a bundle other than the main bundle it is best to use the pathFor
Resource:ofType:inDirectory: method of NSBundle to explicitly specify the folder in
which a specific file/resource exists.
原文地址:http://www.cnblogs.com/iihe602/archive/2013/01/17/2865280.html
IOS NSBundle的使用,注意mainBundle和Custom Bundle的区别的更多相关文章
- NSBundle的使用,注意mainBundle和Custom Bundle的区别
1.[NSBundle mainBundle],文件夹其实是Group,如左侧的树形文件管理器 Build之后,文件直接就复制到了根目录下,于是读取的方法,应该是这样: NSString *earth ...
- 【转】NSBundle的使用,注意mainBundle和Custom Bundle的区别
1.[NSBundle mainBundle],文件夹其实是Group,如左侧的树形文件管理器 Build之后,文件直接就复制到了根目录下,于是读取的方法,应该是这样: NSString *earth ...
- IOS NSBundle 的理解和 mainBundle 类方法详解
常看到类似的 NSString *file = [[NSBundle mainBundle] pathForResource:name ofType:nil]; 这样的代码,用来获取 file 的完全 ...
- iOS 关于nil和Nil及null与<null>的区别
问题是这样的. NSDictionary *sample = [NSJSONSerialization JSONObjectWithData:received options:NSJSONReadin ...
- iOS 杂笔-20(UIView和CALayer的区别与联系)
iOS 杂笔-20(UIView和CALayer的区别与联系) 每个 UIView 内部都有一个 CALayer 在背后提供内容的绘制和显示,并且 UIView 的尺寸样式都由内部的 Layer 所提 ...
- iOS [[NSBundle mainBundle] pathForResource:@"" ofType:@""]无法获取到文件
将一个文件导入到工程中后,用[[NSBundle mainBundle] pathForResource:@"" ofType:@""]来获取到该文件时,一直无 ...
- iOS:NSBundle的具体介绍
NSBundle介绍:它是一个单例类,用来加载资源 bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-i ...
- NSBundle的理解和mainBundle的基本介绍
一.NSBundle NSBundle是cocoa为bundle提供的一个类,bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像.声音.编译好的代码.nib文件.(用户也会把 ...
- IOS NSBundle使用(访问文件夹)
NSBundle的相关信息 1.一个NSBundle代表一个文件夹,利用NSBundle能访问对应的文件夹 2.利用mainBundle就可以访问软件资源包中的任何资源 3.模拟器应用程序的安装路径: ...
随机推荐
- Python---1. 基础数据类型
转载: Py西游攻关之基础数据类型
- php生成二维码的几种方式
一些php生成二维码的方式:1.google开放api:2.php类库PHP QR Code:3.libqrencode:4.QRcode Perl CGI & PHP scripts 1.g ...
- JDBC连接数据库(一)
原文地址http://www.cnblogs.com/hongten/archive/2011/03/29/1998311.html JDBC连接数据库 创建一个以JDBC连接数据库的程序,包含7个步 ...
- testng生成报告ReportNG美化测试报告
testng生成报告ReportNG美化测试报告 testng生成报告ReportNG美化测试报告 ReportNG 是一个配合TestNG运行case后自动帮你在test-output文件内生成一个 ...
- 【android】移植IOS视图响应陀螺仪交互行为
IOS有个很有趣味的特性:背景图片可以响应陀螺仪方向的变化,去改变X.Y轴上的值,从而让整个界面看着充满着灵性.具体步骤是:解锁苹果产品,在IOS7以上,摆动手势,观察桌面背景图片的变化. 刚好,我们 ...
- sql server中的怎么把数值型转换为字符串
①select cast(字段 as varchar) from 表名 ②select convert(varchar(50),字段) from 表名
- laravel + html ajax 多表单字段和图片一起上传
$("#article_push").on('click', function (e){ e.preventDefault(); var stylestr = $('#summer ...
- 用python解析word文件(段落篇(paragraph) 表格篇(table) 样式篇(style))
首先需要安装相应的支持库: 直接在命令行执行pip install python-docx 示例代码如下: import docxfrom docx import Document #导入库 path ...
- VMware Vcenter Server 6.0忘记密码
windows 版Vcenter6.0 重置密码首先要登录到安装Vcenter的windows服务器上 用管理员身份打开CMD命令行 进入VMware VCenter的目录 默认是C:\Program ...
- Spring Boot与数据
SpringBoot 着眼于JavaEE! 不仅仅局限于 Mybatis .JDBC. Spring Data JPA Spring Data 项目的目的是为了简化构建基于 Spring 框架应用的数 ...