zoukankan      html  css  js  c++  java
  • viewDidLoad、viewDidUnload、viewWillAppear、viewDidAppear、viewWillDisappear 和 -viewDidDisappear的区别和使用

     

    首先看一下官方解释:

    - (void)loadView; // This is where subclasses should create their custom view hierarchy if they aren't using a nib. Should never be called directly.

    - (void)viewDidUnload NS_DEPRECATED_IOS(3_0,6_0); // Called after the view controller's view is released and set to nil. For example, a memory warning which causes the view to be purged. Not invoked as a result of -dealloc.

    - (void)viewDidLoad; // Called after the view has been loaded. For view controllers created in code, this is after -loadView. For view controllers unarchived from a nib, this is after the view is set.

     

    - (void)viewWillAppear:(BOOL)animated;    // Called when the view is about to made visible. Default does nothing

    - (void)viewDidAppear:(BOOL)animated;     // Called when the view has been fully transitioned onto the screen. Default does nothing

    - (void)viewWillDisappear:(BOOL)animated; // Called when the view is dismissed, covered or otherwise hidden. Default does nothing

    - (void)viewDidDisappear:(BOOL)animated;  // Called after the view was dismissed, covered or otherwise hidden. Default does nothing

    -viewDidLoad,这个方法在view被加载之后调用,如果没有nib文件,这个方法是在loadView方法被调用之后调用,如果有nib文件,这个方法是在view从nib中加载后调用,总之当一个viewController被初始化后,-viewDidLoad方法仅被调用一次。

    -viewWillAppear,在加载了view之后,在view出现在屏幕之前调用viewWillAppear

    --viewDidAppear,view出现在屏幕之后开始调用

    -viewWillDisappear,是指view将要消失的时候开始调用

    -viewDidDisappear,是指view已经消失后开始调用

    -viewDidUnload,是指一个view被release或被内存警告清除时调用,在dealloc后不会调用

    我们会把一次执行的代码放在viewDidLoad里面,把要多次执行的代码放在viewWillAppear里面


  • 相关阅读:
    CF终于上紫了。。。
    CF567F/51nod2522 上下序列
    bzoj 前100题计划
    CF1110G Tree-Tac-Toe 博弈论、构造
    BZOJ4816 SDOI2017 数字表格 莫比乌斯反演
    UOJ400/LOJ2553 CTSC2018 暴力写挂 边分治、虚树
    Luogu4774 NOI2018 屠龙勇士 ExCRT
    CF1039D You Are Given a Tree 根号分治、二分、贪心
    CF1056E Check Transcription 字符串哈希
    Luogu4345 SHOI2015 超能粒子炮·改 Lucas、数位DP
  • 原文地址:https://www.cnblogs.com/riskyer/p/3271352.html
Copyright © 2011-2022 走看看