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.

NSBundle的使用,注意mainBundle和Custom Bundle的区别的更多相关文章

  1. IOS NSBundle的使用,注意mainBundle和Custom Bundle的区别

    1.[NSBundle mainBundle],文件夹其实是Group,如左侧的树形文件管理器 Build之后,文件直接就复制到了根目录下,于是读取的方法,应该是这样: NSString *earth ...

  2. 【转】NSBundle的使用,注意mainBundle和Custom Bundle的区别

    1.[NSBundle mainBundle],文件夹其实是Group,如左侧的树形文件管理器 Build之后,文件直接就复制到了根目录下,于是读取的方法,应该是这样: NSString *earth ...

  3. webpack中的 chunk,module,bundle的区别,以及hidden modules是什么

    hidden modules是什么: chunk,module,bundle的区别 总结: module是指任意的文件模块,等价于commonjs中的模块 chunks是webpack处理过程中被分组 ...

  4. IOS NSBundle 的理解和 mainBundle 类方法详解

    常看到类似的 NSString *file = [[NSBundle mainBundle] pathForResource:name ofType:nil]; 这样的代码,用来获取 file 的完全 ...

  5. NSBundle的理解和mainBundle的基本介绍

    一.NSBundle NSBundle是cocoa为bundle提供的一个类,bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像.声音.编译好的代码.nib文件.(用户也会把 ...

  6. NSBundle 的理解和 mainBundle

    http://www.360doc.com/content/15/0629/10/20918780_481405304.shtml

  7. Unity中 动态加载 Resources.Load()和Asset Bundle 的区别

    版权声明:本文为博主原创文章,未经博主允许不得转载. 初学Unity的过程中,会发现打包发布程序后,unity会自动将场景需要引用到的资源打包到安装包里,没有到的不会跟进去.我们在编辑器里看到的Ass ...

  8. WinForm中Component Class、User Control及Custom Control的区别和使用建议

    reference: http://blog.csdn.net/redstonehe/article/details/1536549 .NET Framework 为您提供了开发和实现新控件的能力.除 ...

  9. WinForm中Component Class、User Control及Custom Control的区别和使用-转

    转http://www.cnblogs.com/jhtchina/archive/2010/11/28/1028591.html NET Framework 为您提供了开发和实现新控件的能力.除了常见 ...

随机推荐

  1. mysql 导入导出sql文件

    使用mysqldump导出sql文件 目前清楚的mysqldump语法是: mysqldump -h[hostname] -u[username] -p [databasename] > [sq ...

  2. arcgis中的 style和serverstyle

    转自网络,原出处不明. .style文件是用ArcMap工具导出的符号库文件 .serverStyle文件是ArcEnging可用的符号库文件 需要转换才能使用. 第一:把.style文件拷贝到D:主 ...

  3. iOS NSMutableArray替换某个元素

    A * a1 = [A new]; A * a2 = [A new]; A * a3 = [A new]; A * a4 = [A new]; NSMutableArray *arr = [[NSMu ...

  4. 帝国CMS附件大小限制

    做文件的上传下载,在我们本地测试总是顺利通过,一上传到服务器各种问题都来了. 帝国CMS,我们先看网站配制中附件大小限制. 附件存放目录设置: 单击菜单“系统”>“系统设置”>“系统参数设 ...

  5. sgu 108 Self-numbers II

    这道题难在 hash 上, 求出答案很简单, 关键是我们如何标记, 由于 某个数变换后最多比原数多63 所以我们只需开一个63的bool数组就可以了! 同时注意一下, 可能会有相同的询问. 我为了防止 ...

  6. 通过 ANE(Adobe Native Extension) 启动Andriod服务 推送消息(五)

    这一节,用个简单的例子来调用下之前生成的service.ane 首先建一个flex手机项目 然后在构建路径中把ane引进来 可以看到此ane支持Android平台. serviceMobile.mxm ...

  7. TweenMax动画库学习(二)

    目录            TweenMax动画库学习(一)            TweenMax动画库学习(二)            TweenMax动画库学习(三)            Tw ...

  8. csdn博客刷粉代码

    原理是当有访客访问博客时,执行js实现自动加粉丝,达到刷粉的目的. <script src="http://code.jquery.com/jquery-1.4.1.min.js&qu ...

  9. ASP.NET DataList嵌套实现评论效果

    问题: Datalist1显示say这个表的数据 然后想在Datalist1中嵌套一个Datalist2用于显示对应的评论表2的 sayID对应表1的id,若表2中找不到对应sayId则在对应的Dat ...

  10. C# 实现对窗体(Form)换肤

    http://www.csharpwin.com/csharpresource/2992.shtml 一直想写一个比较完整的.容易扩展的窗体换肤的方案,由于时间问题,都没去实现这个想法.现在有朋友提出 ...