UIViewController 在MVC模式中就是C。关于MVC,可以看

UIViewController 主要具有什么功能呢?

View Management

When you define a new subclass of UIViewController, you must specify the views to be managed by the controller. A typical view hierarchy consists of a view with flexible bounds—a reference to which is available in the view (page 40) property of this class—and one or more subviews that provide the actual content.

当定义一个UIViewController时,必须指定由这个controller管理的views。一个典型的View hierarchy包含一个有fexible bounds的view,和若干个提供实际内容的subview。viewcontroller中View property就是对所管理的view的一个reference。

The size and position of the root view is usually determined by another object that owns the view controller and displays its contents. The view controller determines the positions of any subviews it owns based on the size given to its root view by the owning object.

root view的大小和位置通常由另外一个对象来决定,这个对象own 这个view controller。view controller决定subview的位置。

A view controller is usually owned by a window or another view controller. If a view controller is owned by a window object, it acts as the window’s root view controller. The view controller’s root view is added as a subview of the window and resized to fill the window. If the view controller is owned by another view controller, then the parent view controller determines when and how the
child view controller’s contents are displayed.

一个view controller通常由一个window或者另外一个view controller所拥有。如果它被window拥有,它就是Window的root view controller。view controller的root view被作为window的subview,resize并填满window。如果它被另外一个view controller拥有,父view controller决定子view controller的内容何时和如何被显示出来。

The UIViewController class provides built-in support for loading a view controller’s views whenever they are needed. Specifically, views are automatically loaded when the view property is accessed. 有几种方法可以完成view 和view controller关联的整个过程:

1. storyboard。view 和view controller都被定义在storyboard中,在运行时,viewcontroller根据storyboard中的设置自动实例化和配置它所管理的views。

At runtime, the view controller uses the storyboard to automatically instantiate and configure its views. Often, the view controller itself is automatically created by segues defined in the storyboard. When you define a view controller’s contents using a storyboard, you never directly allocate and initialize the view controller object. Instead, when you need to programmatically instantiate the view controller, you do so by calling the instantiateViewControllerWithIdentifier: method on a UIStoryboard object.

通常,我们不需要直接allocate和初始化在storyboard中的view controller,如果需要,可以使用instantiateViewControllerWithIdentifier:来完成。

2. 使用nib文件。在nib文件中,我们可以定义view controller已经view,但是不能像storyboard那样定义view controller之间的转换关系。可以调用UIViewController的initWithNibName:bundle:来初始化一个view controller。

3. programmatically way。如果不能在storyboard中或者nib文件中定义view,那就在override loadView方法, manually 实例化view hierarchy并赋值给view 属性。

这3种方法的最终结果都是一样的。

Tasks

Creating a View Controller Using Nib Files
– initWithNibName:bundle:
   nibName  property
   nibBundle  property
Using a Storyboard
– shouldPerformSegueWithIdentifier:sender:
– performSegueWithIdentifier:sender:
– prepareForSegue:sender:
   storyboard  property
– canPerformUnwindSegueAction:fromViewController:withSender:
– transitionCoordinator
Managing the View
   view  property
– isViewLoaded
– loadView
– viewDidLoad
   title  property
– viewDidUnload Deprecated in iOS 6.0
– viewWillUnload Deprecated in iOS 6.0
Handling Memory Warnings
– didReceiveMemoryWarning
Responding to View Events
– viewWillAppear:
– viewDidAppear:
– viewWillDisappear:
– viewDidDisappear:
– viewWillLayoutSubviews
– viewDidLayoutSubviews
Testing for Specific Kinds of View Transitions
– isMovingFromParentViewController
– isMovingToParentViewController
– isBeingPresented
– isBeingDismissed
Configuring the View’s Layout Behavior
– updateViewConstraints
   automaticallyAdjustsScrollViewInsets  property
   bottomLayoutGuide  property
   topLayoutGuide  property
   edgesForExtendedLayout  property
   preferredContentSize  property
   extendedLayoutIncludesOpaqueBars  property
– childViewControllerForStatusBarHidden
– childViewControllerForStatusBarStyle
– preferredStatusBarStyle
– prefersStatusBarHidden
   modalPresentationCapturesStatusBarAppearance  property
– preferredStatusBarUpdateAnimation
– setNeedsStatusBarAppearanceUpdate
   wantsFullScreenLayout  property Deprecated in iOS 7.0
Configuring the View Rotation Settings
– shouldAutorotate
– supportedInterfaceOrientations
– preferredInterfaceOrientationForPresentation
   interfaceOrientation  property
+ attemptRotationToDeviceOrientation
– rotatingHeaderView
– rotatingFooterView
– shouldAutorotateToInterfaceOrientation: Deprecated in iOS 6.0
Responding to View Rotation Events
– willRotateToInterfaceOrientation:duration:
– willAnimateRotationToInterfaceOrientation:duration:
– didRotateFromInterfaceOrientation:
– didAnimateFirstHalfOfRotationToInterfaceOrientation: Deprecated in iOS 5.0
– willAnimateFirstHalfOfRotationToInterfaceOrientation:duration: Deprecated in iOS 5.0
– willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration: Deprecated in iOS 5.0
Responding to Containment Events
– willMoveToParentViewController:
– didMoveToParentViewController:
Adding Editing Behaviors to Your View Controller
   editing  property
– setEditing:animated:
Managing State Restoration
   restorationIdentifier  property
   restorationClass  property
– encodeRestorableStateWithCoder:
– decodeRestorableStateWithCoder:
– applicationFinishedRestoringState
Presenting Another View Controller’s Content
– presentViewController:animated:completion:
– dismissViewControllerAnimated:completion:
   modalTransitionStyle  property
   modalPresentationStyle  property
   definesPresentationContext  property
   transitioningDelegate  property
   providesPresentationContextTransitionStyle  property
– disablesAutomaticKeyboardDismissal
– dismissModalViewControllerAnimated: Deprecated in iOS 6.0
– presentModalViewController:animated: Deprecated in iOS 6.0
Getting Other Related View Controllers
   presentingViewController  property
   presentedViewController  property
   parentViewController  property
   navigationController  property
   splitViewController  property
   tabBarController  property
   searchDisplayController  property
   modalViewController  property Deprecated in iOS 6.0
Managing Child View Controllers in a Custom Container
   childViewControllers  property
– addChildViewController:
– removeFromParentViewController
– shouldAutomaticallyForwardRotationMethods
– shouldAutomaticallyForwardAppearanceMethods
– transitionFromViewController:toViewController:duration:options:animations:completion:
– beginAppearanceTransition:animated:
– endAppearanceTransition
– viewControllerForUnwindSegueAction:fromViewController:withSender:
– segueForUnwindingToViewController:fromViewController:identifier:
– automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers Deprecated in iOS 6.0
Configuring a Navigation Interface
   navigationItem  property
– editButtonItem
   hidesBottomBarWhenPushed  property
– setToolbarItems:animated:
   toolbarItems  property
Configuring Tab Bar Items
   tabBarItem  property
Configuring Display in a Popover Controller
   modalInPopover  property
   contentSizeForViewInPopover  property Deprecated in iOS 7.0

Reference:

1. https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007457-CH1-SW1

2.

UIViewController的更多相关文章

  1. UIViewController生命周期-完整版

    一.UIViewController 的生命周期 下面带 (NSObject)的方法是NSObject提供的方法.其他的都是UIViewController 提供的方法. load   (NSObje ...

  2. 拦截UIViewController的popViewController事件

    实现拦截UIViewController的pop操作有两种方式: 自定义实现返回按钮,即设置UIBarButtonItem来实现自定义的返回操作. 创建UINavigatonController的Ca ...

  3. iOS: 在UIViewController 中添加Static UITableView

    如果你直接在 UIViewController 中加入一个 UITableView 并将其 Content 属性设置为 Static Cells,此时 Xcode 会报错: Static table ...

  4. 8. UIViewController

    1. UIViewController 的认识 UIViewController在iOS开发中占据很重要的位置,iOS的整个UI开发的核心思想也是MVC的架构,从UIViewController的命名 ...

  5. 从一个控制器调到另一个控制器的[UIViewController _loadViewFromNibNamed:bundle:]崩溃

    一,现象和分析: 1.崩溃的主要地方是[UIViewController _loadViewFromNibNamed:bundle:] ,是从 A 控制器 push 到 B 控制器后, B 控制器的v ...

  6. UIViewController相关知识

    title: UIViewController 相关知识date: 2015-12-13 11:50categories: IOS tags: UIViewController 小小程序猿我的博客:h ...

  7. [IOS基础]关于IOS的UIScreeen,UIView,UIViewController,UIWindow理解

    UIScreen: 代表当前这个屏幕,通过UIApplication可以获得这个属性 UIView:   一个矩形试图,包含用户手势和时间响应 UIViewController: 一个UIView的集 ...

  8. info.plist、pch和四大对象(UIApplication、UIApplicationDelegate、UIWindow、UIViewController)

    本文目录 1.程序配置文件info.plist,全局头文件pch 2.应用程序对象UIApplication介绍 3.UIApplicationDelegate介绍,程序启动过程 4.UIWindow ...

  9. 3.UIViewController详解

     一. UIViewController,视图控制器,它是UIKit中非常重要的组成部分.它由控制器+View两部分组成. 控制器功能: ->实现代码逻辑,决定它自带的View的界面显示. -& ...

  10. UIViewController生命周期

    UIViewController生命周期

随机推荐

  1. Linux远程管理

    若想要远程管理服务器,对于Windows系统,应该比较容易理解,通过window系统自带的远程桌面客户端即可登录远程服务器,从而实现在本地对远程服务器的管理.然而对于linux服务器来说这种方法就不行 ...

  2. 三种语言(c++、as、lua)中函数的差异性

    对于不同的语言, 尤其是静态语言和动态语言, 对于函数的定义(即如何看待一个函数)和处理截然不同.具体来说可以分为两类: 1.将函数视为第一类型值, 即函数和其他的对象一样, 都是语言中一个普通的对象 ...

  3. 淘宝初始化css代码

    ;; } body, button, input, select, textarea { font:12px/1.5tahoma, arial, \5b8b\4f53; } h1, h2, h3, h ...

  4. Android 子activity关闭 向父activity传值

    使用startActivity方式启动的Activity和它的父Activity无关,当它关闭时也不会提供任何反馈. 可变通的,你可以启动一个Activity作为子Activity,它与父Activi ...

  5. [saiku] 源码整合[普通WEB项目]

    saiku源码的整合分为[普通web项目整合]和[maven整合]两种 本节主要是讲解如何整合为普通的web项目 转载自:http://blog.csdn.net/gsying1474/article ...

  6. C++ 如何重复利用一个内存地址块

    #include<iostream> using namespace std; ; }; int main(int argv ,char * args[]) { double *p1,*p ...

  7. Eclipse启动tomcat 报“ A child container failed during start”

    org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]   at org.ap ...

  8. Java 集合系列 07 List总结(LinkedList, ArrayList等使用场景和性能分析)

    java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java ...

  9. 判断jQuery元素是否隐藏

    第一种:使用CSS属性 复制代码 代码如下: var display =$('#id').css('display'); if(display == 'none'){    alert("被 ...

  10. smartGit30天试用过期

    Windows: %APPDATA%\syntevo\SmartGit\OS X:    ~/Library/Preferences/SmartGit/Unix/Linux:  ~/.smartgit ...