View Controller Relationships
Parent-child relationships
Parent-child relationships are formed when using view controller containers. Examples of view
controller containers are UINavigationController, UITabBarController, and UISplitViewController.
You can identify a view controller container because it has a
viewControllers property that is an array of the view controllers it contains.
View controllers in a parent-child relationship form a family. So, a UINavigationController and its
viewControllers are in the same family. A family can have multiple levels. For example, imagine a
situation where a UITabBarController contains a UINavigationController that contains a
UIViewController. These three view controllers are in the same family. The container
classes have access to their children through the viewControllers array, and the children have access
to their ancestors through four properties of UIViewController.
Every UIViewController has a parentViewController property. This property holds the closest view
controller ancestor in the family. Thus, it could return a UINavigationController,
UITabBarController, or a UISplitViewController depending on the makeup of the family tree.
The ancestor-access methods of UIViewController include navigationController,
tabBarController, and splitViewController. When a view controller is sent one of these messages,
it searches up the family tree (using the parentViewController property) until it finds the appropriate
type of view controller container. If there is no ancestor of the appropriate type, these methods return
nil.
Presenting-presenter relationships
The other kind of relationship is a presenting-presenter relationship, which occurs when a view
controller is presented modally. When a view controller is presented modally, its view is added on
top of the view controller’s view that presented it. This is different than a view controller container,
which intentionally keeps a spot open on its interface to swap in the views of the view controllers it
contains. Any UIViewController can present another view controller modally.
There are two built-in properties for managing the relationship between presenter and presentee. A
modally-presented view controller’s presentingViewController will point back to the view
controller that presented it, while the presenter will keep a pointer to the presentee in its
presentedViewController property.
- First, notice that the properties for parent-child relationships can never cross over family boundaries.
- When a view controller is presented modally, the actual presenter is the oldest member of the presenting family.
This behavior explains why the BNRDetailViewController obscures the UINavigationBar when
presented modally but not when presented normally in the UINavigationController’s stack. Even
though the BNRItemsViewController is told to do the modal presenting, its oldest ancestor, the
UINavigationController, actually carries out the task. The BNRDetailViewController is put on top of
the UINavigationController’s view and thus obscures the UINavigationBar.
You can actually override this oldest-ancestor behavior (but only on the iPad). By doing so, you can
specify where the views of the presented view controller family appear on the screen. For example,
you could present the BNRDetailViewController and its navigationController so that it only
obscures the UITableView but not the UINavigationBar.
Every UIViewController has a definesPresentationContext property for this purpose. By default,
this property is NO, which means the view controller will always pass presentation off to its next
ancestor, until there are no more ancestors left. Setting this property to YES interrupts the search for
the oldest ancestor, allowing a view controller to present the modal view controller in its own view.
Additionally, you must set the modalPresentationStyle for the presented view
controller to UIModalPresentationCurrentContext.
- Notice also that the presentingViewController and presentedViewController are valid for every
view controller in each family and always point to the oldest ancestor in the other family.
View Controller Relationships的更多相关文章
- 【IOS笔记】View Controller Basics
		View Controller Basics 视图控制器基础 Apps running on iOS–based devices have a limited amount of screen s ... 
- View Controller Programming Guide for iOS---(四)---Creating Custom Content View Controllers
		Creating Custom Content View Controllers 创建自定义内容视图控制器 Custom content view controllers are the heart ... 
- View Controller Programming Guide for iOS---(三)---Using View Controllers in Your App
		Using View Controllers in Your App Whether you are working with view controllers provided by iOS, or ... 
- View Controller Programming Guide for iOS---(二)---View Controller Basics
		View Controller Basics Apps running on iOS–based devices have a limited amount of screen space for d ... 
- View Controller Programming Guide for iOS---(一)---About View Controllers
		About View Controllers View controllers are a vital link between an app’s data and its visual appear ... 
- iOS 因为reason: 'Pushing the same view controller instance more than once is not supported而奔溃(下)
		这个问题是什么意思呢,之前遇到过几次,但程序再次打开时没有问题,也就没有重视,今天又遇到了,无法忍受啊. 控制台报的错误是:"不支持多次推入相同的视图控制器实例". 什么原因造成的 ... 
- 报错:Failed to instantiate the default view controller for UIMainStoryboardFile 'MainStoryboard' - perhaps the designated entry point is not set?
		原因分析:在StoryBoard中没有一个view controller设置了Initial Scene. 解决方案:在Storyboard中,选择一个view conroller作为story bo ... 
- iOS架构师之路:控制器(View Controller)瘦身设计
		前言 古老的MVC架构是容易被iOS开发者理解和接受的设计模式,但是由于iOS开发的项目功能越来越负责庞大,项目代码也随之不断壮大,MVC的模糊定义导致我们的业务开发工程师很容易把大量的代码写到视图控 ... 
- Model View Controller
		On the iPhone or iPod touch, a modal view controller takes over the entire screen. This is the defau ... 
随机推荐
- 记一些之前忘记积累的问题(fiddler 学习、XP系统不能上网、XP不能装fiddler、注册表快速找到)
			记一些之前忘记积累的问题: fiddler学习:http://www.cnblogs.com/kingwolf_JavaScript/archive/2012/11/07/FiddlerUI.html ... 
- HDFS的运行原理
			简介 HDFS(Hadoop Distributed File System )Hadoop分布式文件系统.是根据google发表的论文翻版的.论文为GFS(Google File System)Go ... 
- C# Lock 解读 (关键是理解最后一句)
			最近在研究.NET分布式缓存代码,正好涉及Lock,看了网上的文章,总结了一些Lock相关的知识,供大家一起学习参考. 一.Lock定义 lock 关键字可以用来确保代码块完成运行,而不会被其 ... 
- 浅谈VB.Net 程序的编译和动态编译
			---恢复内容开始--- 一般,我们都是通过Visual Studio(下面简称vs)来编写和编译vb.net应用程序的,但是,不少的人并不知道vs是通过何种方式编译程序的.今天,我们就来探讨一下编译 ... 
- Python 定位字符串
			一位朋友在玩闯关游戏时遇到如下问题: 感觉考查的就是字符串操作,用string模块就可完成:代码如下: # -*- coding: utf-8 -*- __author__ = 'Evilxr' im ... 
- 使用pngquant命令近乎无损压缩PNG图片大小减少70%左右
			1.安装 wget http://pngquant.org/pngquant-2.8.2-src.tar.gz tar -xzf pngquant-2.8.2-src.tar.gz cd pngqua ... 
- Mac10.9用brew搭建Eclipse4.4+Maven3.2.3+JDK1.8运行环境
			--------------------------------------- 博文作者:迦壹 博客标题:Mac10.9用brew搭建Eclipse4.4+Maven3.2.3+JDK1.8运行环境 ... 
- Fatal error 829---数据库 ID 8,页 (1:80740) 已标记为 RestorePending,可能表明磁盘已损坏(日志备份和热备、双机的重要性)
			问题现象: 在业务数据库中查询:SELECT a.NAME FROM SYSOBJECTS a WHERE a.NAME LIKE '%2015' AND a.XTYPE='u' 提示:消息 21,级 ... 
- 网站推广优化(SEO,网站关键字优化,怎么优化网站,如何优化网站关键字)
			网站推广优化教程100条(完整版)下面介绍新手建站推广完美教程,各位根据自己的实际情况酌情选用: 1.准备个好域名.①.尽量在5位数内,当然也不一定,反正要让用户好记.(看个人):②.尽量用顶级的域名 ... 
- 怎样让SoapHttpClientProtocol不使用系统默认代理
			方法很简单,但找起来很难. 使用SoapHttpClientProtocol类的Proxy属性. 不能设空值,必须设一个新值. 赶脚底层在链接的时候会判断这个属性是不是null,如果null就会用默认 ... 
