presenting controller & presented controller 如何区分

来源:互联网 发布:java中缺省是什么意思 编辑:程序博客网 时间:2024/05/01 21:17

看官方的文档的时候总是看到这连个词,看起来很疑惑。

按照字面的意思和句态,应该是这样理解:presenting controller表示当前正在显示的view controller,而presented controller表示已经显示过的view controller。这样貌似解释的通,但是继续看文档发现这样理解并不能很好地解释下文,于是就开始疑惑,到底是什么意思。于是就google,于是就找到了这个解释:

http://blog.csdn.net/sunshinexyj/article/details/8476248


看了下面的解释恍然大悟,确实是如此,自己怎么就没转过来呢。

1、presenting view controller Vs presented view controller

  当我们在view controller A中模态显示view controller B的时候,A就充当presenting view controller(弹出VC),而B就是presented view controller(被弹出VC)。官方文档建议这两者之间通过delegate实现交互,如果使用过UIImagePickerController从系统相册选取照片或者拍照,我们可以发现imagePickerController和弹出它的VC之间就是通过UIImagePickerControllerDelegate实现交互的。因此我们在实际应用用,最好也遵守这个原则,在被弹出的VC中定义delegate,然后在弹出VC中实现该代理,这样就可以比较方便的实现两者之间的交互。


学习就是一个吃了吐,吐了吃的过程。

下面的内容是2015-09-27 16:56:47 添加的。

可知,对view controller 使用presenting这个效果是类UIViewController内建代码支持的,而且,适用于所有的view controller实例。请原谅我翻译的这么土。

我不知道该怎么翻译presenting和presented这两个词,但是它的效果可以从手机上看到,要不管”presenting"叫“前任”,管presented叫”现任“,好像也不太形象,应为这种叫法是从谁是正在被显示在screen的角度来命名的。但是它却可以正确的指出哪个是哪个。

当时我在试图区分presenting和presented的时候,是从失态区分的,一个是现在分词,表示现在;一个是过去式,表示过去。按照这样的理解,presenting就是当前正在screen上显示的那个,而presented就是presenting之前显示的那个。现在看来这种理解显然是错误的。自以为是的理解让我越看文档越矛盾,于是我崩溃了。。。

view controller programming guide


Support for presenting view controllers is built in to the UIViewController class and is available to all view controller objects. You can present any view controller from any other view controller, although UIKit might reroute the request to a different view controller.Presenting a view controller creates a relationship between the original view controller, known as the presenting view controller, and the new view controller to be displayed, known as the presented view controller. This relationship forms part of the view controller hierarchy and remains in place until the presented view controller is dismissed.



0 0
原创粉丝点击