iOS Xib文件详解

来源:互联网 发布:尚科博文 python 编辑:程序博客网 时间:2024/04/27 23:58

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.

    See Also

    – initWithNibName:bundle:
    nibBundle

  • nibBundle Property

Interacting with Storyboards and Segues

  • storyboard Property
  • - 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

  • view Property
  • - isViewLoaded
  • - loadView
  • - viewDidLoad
  • - loadViewIfNeeded
  • viewIfLoaded Property
  • title Property
  • preferredContentSize Property

Presenting View Controllers

  • modalPresentationStyle Property
  • modalTransitionStyle Property
  • modalInPopover Property
  • - showViewController:sender:
  • - showDetailViewController:sender:
  • - presentViewController:animated:completion:
  • - dismissViewControllerAnimated:completion:
  • definesPresentationContext Property
  • providesPresentationContextTransitionStyle Property
  • - disablesAutomaticKeyboardDismissal

Supporting Custom Transitions and Presentations

  • transitioningDelegate Property
  • - transitionCoordinator
  • - targetViewControllerForAction:sender:
  • presentationController Property
  • popoverPresentationController Property

Responding to View Events

  • - viewWillAppear:
  • - viewDidAppear:
  • - viewWillDisappear:
  • - viewDidDisappear:

Configuring the View’s Layout Behavior

  • - viewWillLayoutSubviews
  • - viewDidLayoutSubviews
  • - updateViewConstraints
  • bottomLayoutGuide Property
  • topLayoutGuide Property
  • edgesForExtendedLayout Property
  • extendedLayoutIncludesOpaqueBars Property
  • automaticallyAdjustsScrollViewInsets Property

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

  • childViewControllers Property
  • - 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

  • presentingViewController Property
  • presentedViewController Property
  • parentViewController Property
  • navigationController Property
  • splitViewController Property
  • tabBarController Property

Handling Memory Warnings

  • - didReceiveMemoryWarning

Managing State Restoration

  • restorationIdentifier Property
  • restorationClass Property
  • - encodeRestorableStateWithCoder:
  • - decodeRestorableStateWithCoder:
  • - applicationFinishedRestoringState

Supporting App Extensions

  • extensionContext Property

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
  • modalPresentationCapturesStatusBarAppearance Property
  • - preferredStatusBarUpdateAnimation
  • - setNeedsStatusBarAppearanceUpdate

Configuring a Navigation Interface

  • navigationItem Property
  • hidesBottomBarWhenPushed Property
  • - setToolbarItems:animated:
  • toolbarItems Property

Configuring Tab Bar Items

  • tabBarItem Property

Adding Editing Behaviors to Your View Controller

  • editing Property
  • - setEditing:animated:
  • - editButtonItem

Accessing the Available Key Commands

  • - addKeyCommand:
  • - removeKeyCommand:

Managing Banner Ads

  • canDisplayBannerAds Property
  • originalContentView Property

Determining Whether the View Controller is Displaying an Ad

  • presentingFullScreenAd Property
  • displayingBannerAd Property

Managing Interstitial Ads

  • + prepareInterstitialAds
  • interstitialPresentationPolicy Property
  • - 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

0 0
原创粉丝点击