美文网首页
NSBundle方法详解 loadnibName

NSBundle方法详解 loadnibName

作者: ChenT | 来源:发表于2016-04-22 10:30 被阅读795次


    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:self options:nil];

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

    }

    相关文章

      网友评论

          本文标题:NSBundle方法详解 loadnibName

          本文链接:https://www.haomeiwen.com/subject/shechttx.html