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. Machine Learning - 第7周(Support Vector Machines)

    SVMs are considered by many to be the most powerful 'black box' learning algorithm, and by posing构建 ...

  2. OneProxy读写分离配置操作手册

    1.确保已配置好主备集群 A)配置 可参考MySQL官方文档(https://dev.mysql.com/doc/refman/5.6/en/replication-howto.html) 或者我的博 ...

  3. linux笔记:目录处理命令ls,mkdir,cd,pwd,rmdir,cp,mv,rm

    linux命令的格式:命令 [-选项] [参数]例:ls -la /etc 命令:ls命令所在路径:/bin/ls功能:显示目录文件用法:ls [-aldh] []参数:-a 查看所有文件,包括隐藏文 ...

  4. python实现微信打飞机游戏

    环境:Ubuntu 16.04 LTS Python 2.7.11 +  Pygame + Pycharm 代码: # -*- coding: UTF-8 -*- import pygame, ran ...

  5. 1029c语言文法

    <程序>→<外部声明>|<程序><外部声明> <外部声明>→<函数定义>|<声明> <函数定义>→< ...

  6. Ubuntu配置LAMP+MediaWiki及常见问题

    /*在实验室觉得文档传来传去太麻烦了,干脆在实验室内部搞个wiki算了,于是网上搜集搜集资料,配了一个,由于时间仓促,mediaWiki比较高级的东西没来的及细看,等以后用的时候再完善吧*/ 环境:U ...

  7. Linux基础:Grep查询&AWK查询

    Grep:搜索文件内匹配指定内容的行 常用的Grep搜索方法: 1. grep "普通搜索内容" file( 或者 cat file|grep "普通搜索内容" ...

  8. Linux下把Mysql和Apache加入到系统服务里

    Linux下注册Apache与MySQL为系统服务 Apache加入到系统服务里面: cp /安装目录下/apache/bin/apachectl /etc/rc.d/init.d/httpd 修改h ...

  9. hdu---(4515)小Q系列故事——世界上最遥远的距离(模拟题)

    小Q系列故事——世界上最遥远的距离 Time Limit: 500/200 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)T ...

  10. toggleClass() 方法做类似于微信扣扣点击语音图标按钮变成切换到语音输入功能,点击键盘图标按钮切换到文字输入状态的效果

    就是这种效果的类似. <html><head><script type="text/javascript" src="/jquery/jqu ...