iOS Xib文件详解
2016-03-27 20:58
531 查看
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instp/UIViewController/nibName
For more information about how the system determines which view controllers to preserve and restore, seeApp
Programming Guide for iOS.
Initializer
The name of the view controller'€™s nib file, if one was specified. (read-only)
OBJECTIVE-C
This property contains the value specified at initialization time to the
The value of this property may be
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
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
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
it looks for a nib file whose name matches the class name without the word ‘€œController’, as in
It looks for a nib file whose name matches the name of the view controller class. For example, if the class name is
it looks for a
NOTE
Nib names that include a platform-specific identifier such as
loaded only on a device of the corresponding type. For example, a nib name of
loaded only on iPad. If your app supports both platform types, you must provide versions of your nib files for each platform.
Available in iOS 2.0 and later.
9.0)
9.0)
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.
7.0) Property
6.0)
6.0)
7.0) Property
6.0)
8.0) Property
8.0)
8.0)
8.0)
5.0)
5.0)
5.0)
8.0) Property
6.0) Property
8.0)
6.0)
9.0)
9.0)
用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
nibNameProperty
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
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 in
MyView.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 a
MyViewController.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 of
MyViewController~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
– initWithNibName:bundle:
nibBundle
nibBundleProperty
Interacting with Storyboards and Segues
storyboardProperty
- shouldPerformSegueWithIdentifier:sender:
- prepareForSegue:sender:
- performSegueWithIdentifier:sender:
- allowedChildViewControllersForUnwindingFromSource:
- childViewControllerContainingSegueSource:
- canPerformUnwindSegueAction:fromViewController:withSender:
- unwindForSegue:towardsViewController:
- viewControllerForUnwindSegueAction:fromViewController:withSender:(iOS
9.0)
- segueForUnwindingToViewController:fromViewController:identifier:(iOS
9.0)
Managing the View
viewProperty
- isViewLoaded
- loadView
- viewDidLoad
- loadViewIfNeeded
viewIfLoadedProperty
titleProperty
preferredContentSizeProperty
Presenting View Controllers
modalPresentationStyleProperty
modalTransitionStyleProperty
modalInPopoverProperty
- showViewController:sender:
- showDetailViewController:sender:
- presentViewController:animated:completion:
- dismissViewControllerAnimated:completion:
definesPresentationContextProperty
providesPresentationContextTransitionStyleProperty
- disablesAutomaticKeyboardDismissal
Supporting Custom Transitions and Presentations
transitioningDelegateProperty
- transitionCoordinator
- targetViewControllerForAction:sender:
presentationControllerProperty
popoverPresentationControllerProperty
Responding to View Events
- viewWillAppear:
- viewDidAppear:
- viewWillDisappear:
- viewDidDisappear:
Configuring the View’s Layout Behavior
- viewWillLayoutSubviews
- viewDidLayoutSubviews
- updateViewConstraints
bottomLayoutGuideProperty
topLayoutGuideProperty
edgesForExtendedLayoutProperty
extendedLayoutIncludesOpaqueBarsProperty
automaticallyAdjustsScrollViewInsetsProperty
Testing for Specific Kinds of View Transitions
- isMovingFromParentViewController
- isMovingToParentViewController
- isBeingPresented
- isBeingDismissed
Configuring the View Rotation Settings
- shouldAutorotate
- supportedInterfaceOrientations
- preferredInterfaceOrientationForPresentation
+ attemptRotationToDeviceOrientation
Adapting to Environment Changes
- collapseSecondaryViewController:forSplitViewController:
- separateSecondaryViewControllerForSplitViewController:
Managing Child View Controllers in a Custom Container
childViewControllersProperty
- addChildViewController:
- removeFromParentViewController
- transitionFromViewController:toViewController:duration:options:animations:completion:
- shouldAutomaticallyForwardAppearanceMethods
- beginAppearanceTransition:animated:
- endAppearanceTransition
- setOverrideTraitCollection:forChildViewController:
- overrideTraitCollectionForChildViewController:
Responding to Containment Events
- willMoveToParentViewController:
- didMoveToParentViewController:
Getting Other Related View Controllers
presentingViewControllerProperty
presentedViewControllerProperty
parentViewControllerProperty
navigationControllerProperty
splitViewControllerProperty
tabBarControllerProperty
Handling Memory Warnings
- didReceiveMemoryWarning
Managing State Restoration
restorationIdentifierProperty
restorationClassProperty
- encodeRestorableStateWithCoder:
- decodeRestorableStateWithCoder:
- applicationFinishedRestoringState
Supporting App Extensions
extensionContextProperty
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.
- registerForPreviewingWithDelegate:sourceView:
- unregisterForPreviewingWithContext:
- previewActionItems
Managing the Status Bar
- childViewControllerForStatusBarHidden
- childViewControllerForStatusBarStyle
- preferredStatusBarStyle
- prefersStatusBarHidden
modalPresentationCapturesStatusBarAppearanceProperty
- preferredStatusBarUpdateAnimation
- setNeedsStatusBarAppearanceUpdate
Configuring a Navigation Interface
navigationItemProperty
hidesBottomBarWhenPushedProperty
- setToolbarItems:animated:
toolbarItemsProperty
Configuring Tab Bar Items
tabBarItemProperty
Adding Editing Behaviors to Your View Controller
editingProperty
- setEditing:animated:
- editButtonItem
Accessing the Available Key Commands
- addKeyCommand:
- removeKeyCommand:
Managing Banner Ads
canDisplayBannerAdsProperty
originalContentViewProperty
Determining Whether the View Controller is Displaying an Ad
presentingFullScreenAdProperty
displayingBannerAdProperty
Managing Interstitial Ads
+ prepareInterstitialAds
interstitialPresentationPolicyProperty
- requestInterstitialAdPresentation
- shouldPresentInterstitialAd
Deprecated
- viewWillUnload(iOS 6.0)
- viewDidUnload(iOS 6.0)
contentSizeForViewInPopover(iOS
7.0) Property
- presentModalViewController:animated:(iOS
6.0)
- dismissModalViewControllerAnimated:(iOS
6.0)
wantsFullScreenLayout(iOS
7.0) Property
- shouldAutorotateToInterfaceOrientation:(iOS
6.0)
- rotatingHeaderView(iOS 8.0)
- rotatingFooterView(iOS 8.0)
interfaceOrientation(iOS
8.0) Property
- willRotateToInterfaceOrientation:duration:(iOS
8.0)
- willAnimateRotationToInterfaceOrientation:duration:(iOS
8.0)
- didRotateFromInterfaceOrientation:(iOS
8.0)
- willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:(iOS
5.0)
- didAnimateFirstHalfOfRotationToInterfaceOrientation:(iOS
5.0)
- willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:(iOS
5.0)
searchDisplayController(iOS
8.0) Property
modalViewController(iOS
6.0) Property
- shouldAutomaticallyForwardRotationMethods(iOS
8.0)
- automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers(iOS
6.0)
- presentMoviePlayerViewControllerAnimated:(iOS
9.0)
- dismissMoviePlayerViewControllerAnimated(iOS
9.0)
Constants
UIModalPresentationStyle
UIModalTransitionStyle
ADInterstitialPresentationPolicy
Exceptions
Notifications
UIViewControllerShowDetailTargetDidChangeNotification
相关文章推荐
- [杂七杂八-iOS]个人总结3.27
- iOS学习之 plist文件的读写
- iOS动态更新方式选择
- iOS --- OpenGLES之图片纹理
- ios 第三方qq登陆,号码禁止授权
- iOS 摇一摇
- iOS 只在主页面显示TabBar
- iOS之使用距离传感器(靠近/远离屏幕-变暗/变亮)
- iOS中 动态热修补技术JSPatch 韩俊强的博客
- iOS中 动态热修补技术JSPatch 韩俊强的博客
- cornerStone查看日志出错:Could not contact repository to read the latest log entries
- iOS开发中的小技巧
- iOS Fmdb数据存储
- iOS开发 ☞ Git使用
- iOS 多线程
- iOS开发--线程通信
- iOS开发-网易滚动导航栏
- iOS 一些第三方库
- 基于面向协议MVP模式下的软件设计-iOS篇
- iOS实战(零):开发社区、文档等资源