The details of init/loadview/viewdidload/viewdidunload don't matter to everyone, and they don't usually get involved, but they are often mentioned during interviews, therefore, it is necessary to understand the lifecycle of viewcontroller. Started from the relationship among init, loadview, viewdidload, viewdidunload, and dealloc
Init Method
Instantiate necessary objects in the init method (following the lazyload idea)
Initialize viewcontroller in init Method
Loadview Method
When a view needs to be displayed but it is nil, viewcontroller calls this method. Do not call this method directly.
If you manually maintain views, you must reload and override this method.
If you use IB to maintain views, you must not override this method by reload.
Loadview and IB build View
If you implement the loadview method in the controller, you may be called by the memory management control at some time when the application is running. If the device memory is insufficient, the View Controller receives the message didreceivememorywarning. The default implementation is to check whether the current controller's view is in use. If its view is not in the current view hierarchy and your controller implements the loadview method, the view will be release, the loadview method is called again to create a new view.
Viewdidload Method
Viewdidload this method is called only when the view is initialized from the NIB file.
Override this method to further customize the view
In iPhone OS 3.0 and later versions, you should also overload viewdidunload to release any indexes on The View.
Call the data model after viewdidload
Viewdidunload Method
This method is called when the system memory is tight (Note: viewcontroller is not dealloc)
When the memory is tight, didreceivemorywarning before iPhone OS 3.0 is the only way to release useless memory, but the viewdidunload method is better in OS 3.0 and later versions.
In this method, set all iboutlet (whether property or instance variables) to nil (the system release view has already been release)
Release other view-related objects in this method, and create others at runtime (but not required by the system) after you set the object to nil (iboutlet only needs to set it to nil, the system release view has already been release)
Viewdidunload is generally considered as the image of viewdidload, because when the view is requested again, viewdidload will be re-executed
Objects release in viewdidunload must be easily re-created (for example, objects created in viewdidload or other methods ), do not release user data or other objects that are difficult to recreate
Dealloc Method
Viewdidunload is not associated with the dealloc method, so dealloc continues to do what it should do.