UIViewController的生命周期
2021-10-27 本文已影响0人
希尔罗斯沃德_董
初始化
- (instancetype)init;
- (instancetype)initWithCoder:([NSCoder](file:///Applications/Xcode.app/Contents/Developer/Documentation/DocSets/com.apple.adc.documentation.iOS.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Classes/NSCoder_Class/index.html#//apple_ref/doc/c_ref/NSCoder)*)decoder; //Returns an object initialized from data in a given unarchiver.self, initialized using the data indecoder
- (instancetype)initWithNibName:(nullableNSString*)nibNameOrNil bundle:(nullableNSBundle*)nibBundleOrNil;
创建view
- (void)loadView;//创建View的方法,当ViewController调用- (void)viewDidLoad方法之前,ViewController会自动调用这个方法创建View;ViewController每次调用self.view get方法的时候都会判断当前View是否已经创建,如果没有的话会调用loadView方法进行创建;这也是解释了为什么init方法里面访问self.view依然能访问到的原因。
view创建完成,开发者可以在这里进行view相关的操作
- (void)viewDidLoad;//这一步view基本上已经创建完成
view即将显示
- (void)viewWillAppear:(BOOL)animated;// Called when the view is about to made visible.Default does nothing.
view即将调用layoutSubviews
// Called just before the view controller's view's layoutSubviews method is invoked. Subclasses can implement as necessary. The default is a no-op.
- (void)viewWillLayoutSubviews API_AVAILABLE(ios(5.0))
view调用layoutSubviews完成
// Called just after the view controller's view's layoutSubviews method is invoked. Subclasses can implement as necessary. The default is a no-op.
- (void)viewDidLayoutSubviews API_AVAILABLE(ios(5.0))
view显示完成
- (void)viewDidAppear:(BOOL)animated;// Called when the view has been fully transitioned onto the screen. Default does nothing
view将要消失
- (void)viewWillDisappear:(BOOL)animated;// Called when the view is dismissed, covered or otherwise hidden. Default does nothing
view已经消失
- (void)viewDidDisappear:(BOOL)animated;// Called after the view was dismissed, covered or otherwise hidden. Default does nothing
内存警告
- (void)didReceiveMemoryWarning;// Called when the parent application receives a memory warning. On iOS 6.0 it will no longer clear the view by default.
viewController销毁
- (void)dealloc;