Today, we summarize the View Controller lifecycle and AutoLayout, which is the 8th section of the course.
1. View Controller Lifecycle
In fact, after listening to the course two times, I still can not accurately summarize the life cycle of each controller is how long. Controller, the C in MVC, begins the life cycle of the controller after MVC is created, which is easy to understand. But what I'm puzzled about is the end of the MVC life cycle.
- How do you define the results of the MVC life cycle first? The Deinit function of the controller is called (memory free)? Or is it the view disapper? For MVC, which calls segue, as long as the MVC is removed from the desktop (disapper), it will no longer appear, because every call to Segue is a new MVC generation. The Disppear and deinit of MVC are not at the same time, as seen in the classroom examples. When MVC disappear, it does not call Deinit until a new MVC of the same type is generated, and the disappear MVC is init.
- I think it's time to define the end of the life cycle of the controller based on memory release. But the question is, is this memory release time-definite?
Now these two questions themselves still can not answer, can only consult others later or in the time question slowly pondering. But this is not the focus of this lesson. The focus of this lesson is to let you know the main operational nodes of the MVC lifecycle, the corresponding APIs, and then implement the specific work by overwriting the appropriate API functions.
To summarize, there are several stages in the View controller's lifecycle:
- Instantiated (from storyboard usually)
- Awakefromnib
- Segue Preparation happens
- Outlets Get Set
- Viewdidload
- These pairs'll be called each time your controller ' s view goes on/off screen ...
- Viewwillappear and Viewdidappear
- Viewwilldisappear and Viewdiddisappear
- These ' geometry changed "methods might is called at any time after viewdidload ...
- Viewwilllayoutsubviews (... then AutoLayout happens and then ...) viewdidlayoutsubviews
- If memory Get low, you might get ...
- Didreceivememorywarning
2. AutoLayout
In fact, this lesson does not say much about AutoLayout. The main thing is size class. The size class concept is easy to understand.
The inherited protocol is uitraitenvironment, and this protocol has an attribute traitcollection, an API Traitcollectiondidchange.
This blog has a good knowledge of the compact and regular: Http://www.learnswift.io/blog/2014/6/12/size-classes-with-xcode-6-and-swift
Read it often.
Stanford IOS Learn Notes-5