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 -
nibName
PropertyThe 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 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
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:-
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.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 ofMyViewController~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.
See Also
-
-
nibBundle
Property -
-
storyboard
Property -
-
view
Property -
viewIfLoaded
Property -
title
Property -
preferredContentSize
Property -
-
modalPresentationStyle
Property -
modalTransitionStyle
Property -
modalInPopover
Property -
definesPresentationContext
Property -
-
transitioningDelegate
Property -
presentationController
Property -
popoverPresentationController
Property -
-
bottomLayoutGuide
Property -
topLayoutGuide
Property -
edgesForExtendedLayout
Property -
extendedLayoutIncludesOpaqueBars
Property -
automaticallyAdjustsScrollViewInsets
Property -
-
childViewControllers
Property -
-
presentingViewController
Property -
presentedViewController
Property -
parentViewController
Property -
navigationController
Property -
splitViewController
Property -
tabBarController
Property -
-
restorationIdentifier
Property -
restorationClass
Property -
-
extensionContext
Property -
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.
-
navigationItem
Property -
hidesBottomBarWhenPushed
Property -
toolbarItems
Property -
-
tabBarItem
Property -
-
editing
Property -
-
canDisplayBannerAds
Property -
originalContentView
Property -
-
presentingFullScreenAd
Property -
displayingBannerAd
Property -
-
interstitialPresentationPolicy
Property -
-
- 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) -