简体   繁体   中英

In what order are view methods called when transitioning from one view controller to another?

When I transition from one view controller (let's call it MasterViewController ) to another (called DetailViewController ), in what order are the viewWillDisappear: , viewWillAppear: , etc. methods on each controller called?

I suspect some of the cleanup code called when my master view disappears is interfering with the initialization code in my detail view. I've looked through Apple's documentation but can't find any information involving multiple view controllers like this.

I created a simple UINavigationController-based project and added some NSLog statements to find out what order they get called in.

  1. Master prepareForSegue:
  2. Detail viewDidLoad
  3. Master viewWillDisappear:
  4. Detail viewWillAppear:
  5. The new view is displayed (with or without animation)
  6. Master viewDidDisappear: (after animation is finished)
  7. Detail viewDidAppear:

However, when switching between views using a UITabViewController , the order is different:

  1. SecondTab viewDidLoad
  2. SecondTab viewWillAppear:
  3. FirstTab viewWillDisappear:
  4. The new view is displayed.
  5. FirstTab viewDidDisappear:
  6. SecondTab viewDidAppear:

So it seems that you cannot always count on these events occuring in the same order - it can vary depending on the nature of the view controllers you are transitioning between.

Are there any important points that I missed here?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM