两个视图控制器之间的viewDidAppear和viewDidDis的回调序列 [英] the callback sequence of viewDidAppear and viewDidDisappear between two view controllers

查看:92
本文介绍了两个视图控制器之间的viewDidAppear和viewDidDis的回调序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,至少有两种方法可以在另一个UIViewController上呈现UIViewController,首先是使用presentModalViewController:animated:on UIViewController,另一种是使用pushViewController:animated:在UINavigationController上,当2视图控制器改变它们的外观时,出现/消失回调的调用序列是不同的。下面是一个例子,A是一个UINavigationController,B是一个普通的视图控制器,实际的回调序列是:

(1)A使用presentModalViewController:animated:显示B:

As I know, there are at least two ways to present a UIViewController on another UIViewController, first is using presentModalViewController:animated: on UIViewController, another is using pushViewController:animated: on UINavigationController, it seems when 2 view controller changing their appearance, the invoke sequence of appear/disappear callbacks are different. Following is an example, A is a UINavigationController, and B is a normal view controller, the actual callback sequence are:
(1) A using presentModalViewController:animated: to show B:

[B viewWillAppear];  
[A viewWillDisappear];  
[B viewDidAppear];  
[A viewDidDisappear];

(2)使用pushViewController:animated:显示B:

(2) A using pushViewController:animated: to show B:

[A viewWillDisappear];  
[B viewWillAppear];  
[A viewDidDisappear];  
[B viewDidAppear];

所以我的问题是,这些不同的回调序列是否稳定,或者我们没有明确的序列依靠?如果它们稳定,是否有任何文件提到这种行为?
有人可以帮忙吗?谢谢高级!

So my question is that, are these different callback sequence stable, or there are no definite sequence we can rely on? If they are stable, is there any document mentions this behavior? Can anyone help? Thanks in advanced!

推荐答案

UIKit 应该在主线程上工作,所以我想这个序列对于当前的SDK版本是稳定的,。但是,只要行为没有记录(并且据我所知),我认为它可能会在没有通知的情况下发生变化。

UIKit should work on the main thread, so I guess that the sequence is stable, for the current SDK version. However, as long as the behavior is not documented (and it is not to my knowledge), I would consider it subject to change without a notice.

我只是好奇;为什么你需要这些方法的确定性序列?也许你可以找到一种解决方法(这可能是一种更好的方法)。

I'm just curious; why do you need a deterministic sequence of those methods? Perhaps you can find a workaround (which might a better way of doing it).

这篇关于两个视图控制器之间的viewDidAppear和viewDidDis的回调序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆