zoukankan      html  css  js  c++  java
  • 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];// 因为返回的是数组

    }

     

    小白的转变
  • 相关阅读:
    四则运算题目的程序
    Github注册账户过程
    目前流行的源程序版本管理软件和项目管理软件都有哪些?各有什么优缺点?
    学习进度总结
    学习进度总结
    7月29 日实习日志及总结
    7月28日实习日志
    7月27实习日志
    7月26日实习日志
    7月25日实习日志
  • 原文地址:https://www.cnblogs.com/CCJ4EVER/p/5038205.html
Copyright © 2011-2022 走看看