the callback sequence of viewDidAppear and viewDid

2019-07-07 03:39发布

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) 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!

2条回答
虎瘦雄心在
2楼-- · 2019-07-07 03:49

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).

查看更多
劫难
3楼-- · 2019-07-07 04:12

You will definitely want to implement some form of synchronization to enforce what you want to do. Relying on Apple's calling sequence of these functions is just asking for trouble.

查看更多
登录 后发表回答