美文网首页
控制器切换时的方法执行顺序

控制器切换时的方法执行顺序

作者: 薛定谔的汪汪 | 来源:发表于2018-12-18 15:03 被阅读0次

    一、FirstViewController:

    (1):viewWillAppear:
    (2):viewDidAppear:
    (3):viewWillDisappear:
    (4):viewDidDisappear:

    二、SecondViewController:

    (5):viewWillAppear:
    (6):viewDidAppear:
    (7):viewWillDisappear:
    (8):viewDidDisappear:

    三、两控制器的切换:

    A.切换方式一:【push】与【pop】

    (a):FirstViewController首次显示时:

    image.png

    viewWillAppear: ----> viewDidAppear:
    即(1)--->(2)

    (b):FirstViewController ------【push】------> SecondViewController时:

    push

    (3)--->(5)--->(4)--->(6)
    解读:
    FirstViewController 即将消失 ------>
    SecondViewController即将出现 ------>
    FirstViewController 彻底消失 ------>
    SecondViewController彻底出现

    (c):SecondViewController ------【pop】------> FirstViewController时:

    pop

    (7)--->(1)--->(8)--->(2)
    解读:
    SecondViewController 即将消失 ------>
    FirstViewController 即将出现 ------>
    SecondViewController 彻底消失 ------>
    FirstViewController 彻底出现

    B.切换方式二:【present】与【dismiss】

    (a):FirstViewController首次显示时:

    image.png

    viewWillAppear: ----> viewDidAppear:
    即(1)--->(2)

    (b):FirstViewController ------【present】------> SecondViewController时:

    present

    (3)--->(5)--->(6)--->(4)
    解读:
    FirstViewController 即将消失 ------>
    SecondViewController即将出现 ------>

    SecondViewController彻底出现 ------>
    FirstViewController 彻底消失

    (c):SecondViewController ------【dismiss】------> FirstViewController时:

    dismiss

    (7)--->(1)--->(2)--->(8)
    解读:
    SecondViewController 即将消失 ------>
    FirstViewController 即将出现 ------>
    FirstViewController 彻底出现 ------>

    SecondViewController 彻底消失

    总结:
    【push/pop】与【present/dismiss】的区别:
    (A)切换方向上
    【push/pop】:默认界面左右切换;
    【present/dismiss】:默认界面上下切换;
    (B)方法执行顺序
    【push/pop】:
    push:(3)--->(5)--->(4)--->(6)
    pop:(7)--->(1)--->(8)--->(2)


    push与pop

    【present/dismiss】:
    present:(3)--->(5)--->(6)--->(4)
    dismiss:(7)--->(1)--->(2)--->(8)


    present与dismiss

    相关文章

      网友评论

          本文标题:控制器切换时的方法执行顺序

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