美文网首页
UIViewController的生命周期

UIViewController的生命周期

作者: 希尔罗斯沃德_董 | 来源:发表于2021-10-27 22:35 被阅读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;
    

    相关文章

      网友评论

          本文标题:UIViewController的生命周期

          本文链接:https://www.haomeiwen.com/subject/uqlbaltx.html