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.
-
- initWithNibName:bundle:Designated Initializer -
nibNamePropertyThe name of the view controller'€™s nib file, if one was specified. (read-only)
Declaration
OBJECTIVE-C
@property(nonatomic, readonly, copy) NSString *nibNameDiscussion
This property contains the value specified at initialization time to the
initWithNibName:bundle:method. The value of this property may benil.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
loadViewmethod 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.nibextension) 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:-
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 inMyView.nib. -
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 aMyViewController.nibfile.
NOTE
Nib names that include a platform-specific identifier such as
~iphoneor~ipadare loaded only on a device of the corresponding type. For example, a nib name ofMyViewController~ipad.nibis 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.
See Also
-
-
nibBundleProperty -
-
storyboardProperty -
-
viewProperty -
viewIfLoadedProperty -
titleProperty -
preferredContentSizeProperty -
-
modalPresentationStyleProperty -
modalTransitionStyleProperty -
modalInPopoverProperty -
definesPresentationContextProperty -
-
transitioningDelegateProperty -
presentationControllerProperty -
popoverPresentationControllerProperty -
-
bottomLayoutGuideProperty -
topLayoutGuideProperty -
edgesForExtendedLayoutProperty -
extendedLayoutIncludesOpaqueBarsProperty -
automaticallyAdjustsScrollViewInsetsProperty -
-
childViewControllersProperty -
-
presentingViewControllerProperty -
presentedViewControllerProperty -
parentViewControllerProperty -
navigationControllerProperty -
splitViewControllerProperty -
tabBarControllerProperty -
-
restorationIdentifierProperty -
restorationClassProperty -
-
extensionContextProperty -
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.
-
navigationItemProperty -
hidesBottomBarWhenPushedProperty -
toolbarItemsProperty -
-
tabBarItemProperty -
-
editingProperty -
-
canDisplayBannerAdsProperty -
originalContentViewProperty -
-
presentingFullScreenAdProperty -
displayingBannerAdProperty -
-
interstitialPresentationPolicyProperty -
-
- viewWillUnload(iOS 6.0) -
- viewDidUnload(iOS 6.0) -
- presentModalViewController:animated:(iOS 6.0) -
- dismissModalViewControllerAnimated:(iOS 6.0) -
- rotatingHeaderView(iOS 8.0) -
- rotatingFooterView(iOS 8.0) -
- didRotateFromInterfaceOrientation:(iOS 8.0) -
4万+

被折叠的 条评论
为什么被折叠?



