iOS Xib文件详解

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instp/UIViewController/nibName


用xib这种方式是需要加载xib文件的。加载xib文件有两种方法:

// 第一种方法(较为常用)
CYLView *view = [[[NSBundle mainBundle] loadNibNamed:@"CYLView" owner:nil options:nil] firstObject]; // CYLView代表CYLView.xib,代表CYLView这个类对应的xib文件。这个方法返回的是一个NSArray,我们取第一个Object或最后一个(因为这个数组只有一个CYLView没有其他对象)就是需要加载的CYLView。

// 第二种方法
UINib *nib = [UINib nibWithNibName:@"CYLView" bundle:nil];
NSArray *objectArray = [nib instantiateWithOwner:nil options:nil];
CYLView *view = [objectArray firstObject];



For more information about how the system determines which view controllers to preserve and restore, seeApp Programming Guide for iOS.

Configuring a View Controller Using Nib Files

  • - initWithNibName:bundle:  Designated Initializer
  • nibName  Property

    The name of the view controller'€™s nib file, if one was specified. (read-only)

    Declaration

    OBJECTIVE-C

    @property(nonatomic, readonly, copy) NSString *nibName

    Discussion

    This property contains the value specified at initialization time to the initWithNibName:bundle: method. The value of this property may be nil.

    If you use a nib file to store your view controller'€™s view, it is recommended that you specify that nib file explicitly when initializing your view controller. However, if you do not specify a nib name, and do not override the loadView method in your custom subclass, the view controller searches for a nib file using other means. Specifically, it looks for a nib file with an appropriate name (without the .nib extension) and loads that nib file whenever its view is requested. Specifically, it looks (in order) for a nib file with one of the following names:

    1. If the view controller class name ends with the word ‘Controller’, as in MyViewController, it looks for a nib file whose name matches the class name without the word ‘€œController’, as in MyView.nib.

    2. It looks for a nib file whose name matches the name of the view controller class. For example, if the class name is MyViewController, it looks for a MyViewController.nib file.

    NOTE

    Nib names that include a platform-specific identifier such as ~iphone or ~ipad are loaded only on a device of the corresponding type. For example, a nib name of MyViewController~ipad.nib is loaded only on iPad. If your app supports both platform types, you must provide versions of your nib files for each platform.

    Availability

    Available in iOS 2.0 and later.

  • nibBundle  Property

Managing the View

Getting Other Related View Controllers

Handling Memory Warnings

Supporting App Extensions

Working With 3D Touch Previews and Preview Quick Actions

The methods in this task group are available on devices that support 3D Touch. The end-user terminology for the views presented during the phases of force-based touches includes peek and pop. For clarity here, and to align with the API names, this document uses the corresponding terms preview and commit view. To learn more about 3D Touch, read Adopting 3D Touch on iPhone.

Configuring a Navigation Interface

Configuring Tab Bar Items

Adding Editing Behaviors to Your View Controller

Accessing the Available Key Commands

Managing Banner Ads

Determining Whether the View Controller is Displaying an Ad


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值