Search code examples
iphoneipaduiviewcontroller

The callback sequence of viewDidAppear and viewDidDisappear between two view controllers


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?


Solution

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