I. loadView
When you do not use xib to create a view, there are two situations. 1. If the method is not reloaded in the implementation file, the default operation of this method is to create a UIView for the current VC view. Second, to recreate this method, you must create a UIView for the current VC in this method, and do not call super when rewriting this function. Some controls can be loaded in this function, but it is not recommended to add them here.
- (void)loadView{ // If you create your views manually, you MUST override this method and use it to create your views. // If you use Interface Builder to create your views, then you must NOT override this method. UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; [view setBackgroundColor:[UIColor whiteColor]]; self.view = view; [view release]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 100, 40)]; label.backgroundColor = [UIColor redColor]; [self.view addSubview:label]; [label release]; }
Ii. viewDidload
This function is called whether it is xib or loadview. In most cases, perform subsequent initialization of xib.
3. viewDidUnload
This function is opposite to viewDidload. When the program memory is insufficient, this function is called by the controller. Since the controller usually stores the reference of view-related objects or other objects created at runtime, you must use this function to discard the ownership of these objects for memory reclaim. But do not release data that is hard to reconstruct.
Summary:
1. You can directly load the control in viewDidload without overwriting loadview, whether created using xib or pure code. The pure code only needs to use the init function during initialization.
2. (loadView/nib file) to load the view to the memory --> viewDidLoad function to further initialize these views --> when the memory is insufficient, call the viewDidUnload function to release views
--> When you need to use a view, the first step is returned to this alternating loop.
Reference: http://www.dreamingwish.com/dream-2011/correct-online-information-error-loadview-viewdidload-viewdidunload.html