简体   繁体   English

每次在xCode 9.4和iOS 11中调用的ViewDidLoad()方法

[英]ViewDidLoad() method called every time in xCode 9.4 and iOS 11

Whenever we present or push from SourceViewController to DestinationViewController , ViewDidLoad() method called every time in DestinationViewController in xCode 9.4 and iOS 11 or later. 每当我们present或从SourceViewController push送到DestinationViewController ,每次都会在xCode 9.4iOS 11或更高版本的DestinationViewController中调用ViewDidLoad()方法。 And when we pop or dismiss from DestinationViewController to SourceViewController , viewDidLoad() method not called. 当我们从DestinationViewController弹出或关闭到SourceViewController ,未调用viewDidLoad()方法。

ViewDidload method only called only when the view loads first time. 仅在第一次加载视图时才调用ViewDidload方法。 When you present or push it loads the view so, it calls viewdidload. 当您展示或推送时,它会加载视图,因此会调用viewdidload。 But when you pop it release the view. 但是当您弹出它时,将释放视图。

Here is the lifecycle of UIViewController . 这是UIViewController的生命周期。

  • ViewDidLoad - Called when you create the class and load from xib. ViewDidLoad创建类并从xib加载时调用。 (Either present or push) This method called for initial setup and only one time called. (存在或推送)此方法要求进行初始设置,而仅调用一次。
  • ViewWillAppear - Called right before your view appears, this will be called every time your view is about to appear on the screen. ViewWillAppear在视图出现之前立即调用,每次视图将出现在屏幕上时都会调用此方法。
  • ViewDidAppear - Called after the view appears - great place to start an animations or the loading of external data from an API. ViewDidAppear在视图出现后调用-是启动动画或从API加载外部数据的好地方。 This will be also called every time after ViewWillAppear when view appeared on the screen. 每当在屏幕上出现视图时,每次在ViewWillAppear之后也将调用此方法。
  • ViewWillDisappear/DidDisappear - Same idea as ViewWillAppear/ViewDidAppear only when view is about to dismiss or pop. ViewWillDisappear/DidDisappear仅当视图即将关闭或弹出时,与ViewWillDisappear/DidDisappear相同的想法。
  • ViewDidUnload/ViewDidDispose - In Swift or Objective C, this is where you do your clean-up and release of stuff, but this is handled automatically so not much you really need to do here. ViewDidUnload/ViewDidDispose在Swift或Objective C中,您可以在此处进行清理和发布内容,但是这是自动处理的,因此您在这里实际上不需要做很多事情。

Read Apple documentation for details. 有关详细信息,请阅读Apple 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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