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. imageview圆角的实现

    介绍一种简单的.另类的实现,就是把图片在显示前处理成圆角的,但是不改变存储的图片.相当于经过了图像过滤. 需要调用的图像工具类是 package com.gaosi.util; /** * @auth ...

  2. mac 下 parallels 虚拟机 ubuntuServer 安装 parallels tools

    mac 下 parallels 虚拟机 ubuntuServer 安装 parallels tools 1. 先点击ubuntu 虚拟机右下角的设置 -----安装 parallels tools - ...

  3. PV UV IP含义及区别

    --------首先来看看ip.uv和pv的定义---------- PV(访问量):即Page View, 即页面浏览量或点击量,用户每次刷新即被计算一次. UV(独立访客):即Unique Vis ...

  4. 如何增加Asp.Net Core生成的模板网站中用户信息表中的列(AspNetUsers)

    环境: 1.VS2015 Community 14.0.25431.01 Update 3; 2.其他环境(具体哪一个影响不太清楚,都列在这儿) 使用的系统模板 利用系统提供的模板,并选择个人身份验证 ...

  5. 打开Eclipse时出现"The Eclipse executable launcher was unable to locate its companion shared library"情况的解决办法

    在网上有坑,各种解决方法都有,但似乎我这台64位机器不太给面子,都不能解决: 结果自己找到了解决办法,总结了一下,大多数软件出问题,如果卸载了重新装还是出现问题,一般都是注册表残留的问题: 将ecli ...

  6. jqury.jqzoom插件--放大镜

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  7. js中event.target和event.srcElement的区别

    看了很多资料绝对结果就是 firefox 下的 event.target = IE 下的 event.srcElement jquery中的event.target属性的作用是获取到出发事件的元素.j ...

  8. Qt之QSystemTrayIcon

    简述 QSystemTrayIcon类为应用程序在系统托盘中提供一个图标. 现代操作系统通常在桌面上提供一个特殊的区域,称为系统托盘或通知区域,长时间运行的应用程序可以显示图标和短消息. 简述 内容 ...

  9. JDK1.7-LinkedList循环链表优化

    最近在看jdk1.7的时候,发现LinkedList 和1.6中的变化. 首先,简单介绍一下LinkedList: LinkedList是List接口的双向链表实现.由于是链表结构,所以长度没有限制: ...

  10. PHP的那些坑

    1.urlencode urlencode编码的对象必须是utf-8编码.如果是其它格式的编码就会出现乱码. 2.array_merge 一般来说,array_merge就是把两个或两个以上的数组组合 ...