from:http://www.jianshu.com/p/fcfbd4919b0bthe life cycle of Viewcontroller is related to the preservation of data, refresh of view, etc., very importantFirst, ARC environment
- The life cycle of a single viewcontroller
- Initwithcoder: (Nscoder *) Adecoder: (If using storyboard or xib)
- Loadview: Load View
- Viewdidload:view Loading complete
- Viewwillappear: The controller's view will be displayed
- Viewwilllayoutsubviews: Controller's view will layout child controls
- Viewdidlayoutsubviews: Controller's view layout child controls complete
这期间系统可能会多次调用viewWillLayoutSubviews 、 viewDidLayoutSubviews 俩个方法
- Viewdidappear: View full display of controller
- Viewwilldisappear: When the controller's view is about to disappear
这期间系统也会调用viewWillLayoutSubviews 、viewDidLayoutSubviews 两个方法
- Viewdiddisappear: When the controller's view disappears completely
- multiple viewcontrollers jump
- When we click on Push, we first load the next interface before we call the interface's vanishing method
- Initwithcoder: (Nscoder *) Adecoder:
ViewController2 (if created with Xib)
- Loadview:
ViewController2
- viewdidload:
ViewController2
- viewwilldisappear: ViewController1 will disappear
- viewwillappear:
ViewController2 will appear
- Viewwilllayoutsubviews
ViewController2
- viewdidlayoutsubviews
ViewController2
- viewwilllayoutsubviews: ViewController1
- viewdidlayoutsubviews: ViewController1
- viewdiddisappear: ViewController1 completely disappears
- viewdidappear:< Code>viewcontroller2 appears completely
- Summary:
-Entire controller declaration period: viewdidlayoutsubviews, Viewwilllayoutsubviews, Viewwillappear, Viewdidload, Viewdidappear, Viewwilldisappear, viewdiddisappear
Second, non-ARC environment
- Didreceivememorywarning:
- When the app receives a memory warning, it sends a message to the view controller.
- The app never calls this method directly, but takes a call when the system determines that there is not enough memory available.
如果你想覆写这个方法来释放一些控制器使用的额外内存,你应该在你的实现方法中调用父类的实现方法。
- Viewwillunload:
(iOS6废除)
- Called when a view of the controller is removed
- The view will no longer be purged under low memory conditions so this method will not be called again.
- Before IOS5, when the low memory situation occurs, the current controller's view Tumen is no longer required, the system will selectively remove these views from these memory. This method is called to perform some empty tasks before the view is actually destroyed. Like what
你想要使用这个方法去清空视图的观察者或通知或者记录视图的状态以便当重新读取的时候恢复。
- After iOS6, you no longer need to clear a reference to the view. Therefore, some other methods of cleanup, such as emptying the observer, are not necessary.
- Viewdidunload:
(iOS6废除)
- Called when the view is removed from memory
- The view is no longer destroyed in the memory of the ground so this method is no longer called
- Prior to IOS5, the current attempt to view the controller's views was no longer required, and the system would be invoked after the view controller's view was destroyed. This method allows you to perform some last chance of emptying the task if your view controller stores separate references to views or child controls, you should use this method to release these references.
你也可以使用这个方法去消除一些你再创建视图时候所创建的但是当视图不再的时候不再需要的关于对象的引用。你不应该使用这个方法去释放用户数据或者一些不能轻易被重新创建的数据。
- After iOS6, it is not necessary to empty references to views and other objects in the controller.
- When this method is called, the properties of the view are empty.
Wen/mitchell (author of Jane's book)
Original link: http://www.jianshu.com/p/fcfbd4919b0b
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".
Ios-viewcontroller life cycle