博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NSBundle和XIB加载
阅读量:7055 次
发布时间:2019-06-28

本文共 1292 字,大约阅读时间需要 4 分钟。

NSBundle 类中,苹果给出的解释是:
An 
NSBundle object represents a location in the file system that groups code and resources that can be used in a program. 
NSBundle objects locate program resources, dynamically load and unload executable code, and assist in localization. You build a bundle in Xcode using one of these project types: Application, Framework, plug-ins.
大概翻译过来:
NSBundle 对象指代相应应用程序下的所有可用的文件系统。就是说,可以用NSBundle操作应用程序下,所有可用的资源(包括,xib文件,数据文件,图片 等)。
 
NSBundle 英语中的解释是:“捆,束”的意思,那我们可以理解为:
NSBundle是将程序中所有资源捆在一起的对象。
 

mainBundle方法:

Returns the NSBundle object that corresponds to the directory where the current application executable is located.

+ (NSBundle *)mainBundle

该方法:返回NSBundle 对象;可以用该对象来返回应用程序可操作的路径和文件。

 

NSBundle *myBundle = [NSBundle mainBundle];

已经包括了很多已经封装好的方法。

边学习,边了解把。

1、loadNibNamed方法:

- (NSArray *)loadNibNamed:(NSString *)name owner:(id)owner options:(NSDictionary *)options

参数:

name:nib文件的名称

owner:指定name参数所指代的nib文件的File's Owner

options:当nib文件开始时,需要的数据

返回值:返回符合对象的数组。

例子:初始化一个View

 

CustomCell *cell=(CustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomCellTableIdentifier];

if (cell==nil) {

NSArray *nib=[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:selfoptions:nil];

cell=[nib objectAtIndex:0];// 因为返回的是数组

}

 

转载于:https://www.cnblogs.com/CCJ4EVER/p/5038205.html

你可能感兴趣的文章
[转]Kernel. EXPORT_SYMBOL解析
查看>>
caffe 入门实例1 如何调参数
查看>>
苹果创新并未终结 离开乔布斯一样优秀
查看>>
关于for...in... 和 for..of...的使用
查看>>
良序集的一节
查看>>
《常微分方程教程》例2.3.1
查看>>
一个用原生JS造的轮播图插件
查看>>
hadoop集群环境搭建-hadoop之伪分布搭建环境
查看>>
动态编译
查看>>
分享:一个基于NPOI的excel导入导出组件(强类型)
查看>>
数据结构实验之二叉树的建立与遍历
查看>>
C++基础之迭代器
查看>>
杂题 洛谷P2018 消息传递
查看>>
算法笔记 --- Radix Sort
查看>>
Jetty的配置
查看>>
scala函数等号省略
查看>>
通过AutoConfig实现Form Server配置文件的修改 【转载】
查看>>
20165324 2017-2018-2 《Java程序设计》课程总结
查看>>
8-unittest中case管理
查看>>
ExtJs XTemplate
查看>>