ViewDidAppear and viewDidDisappear callback sequence between two view controllers

As I know, there are at least two ways to present a UIViewController on another UIViewController, first uses presentModalViewController: animated: on UIViewController, the other uses pushViewController: animated: on UINavigationController, it seems when 2 view controllers change their appearance, causing the callback to appear / disappear different. The following is an example: A is the UINavigationController, and B is the normal view controller, the actual callback sequence:
(1) A using presentModalViewController: animated: to display B:

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

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

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

So my question is: are these different callback sequences stable, or is there no specific sequence that we can rely on? If they are stable, is there a document in the document? Can anyone help? Thanks, advanced!

+3
source share
2 answers

UIKit should work on the main thread, so I assume the sequence is stable for the current version of the SDK . However, as long as the behavior is not documented (and as far as I know), I would consider it subject to change without notice.

I'm just curious; why do you need a deterministic sequence of these methods? Perhaps you can find a workaround (which could do this better).

0
source

You will definitely want to implement some form of synchronization to ensure what you want to do. Building on Apple, the defiant sequence of these features simply asks about problems.

0
source

Source: https://habr.com/ru/post/918788/


All Articles