NSBundle和XIB加载

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值