iOS UIViewController 生命周期 8个函数

xiaoxiao2021-02-27  733

ViewController 生命周期

 

import UIKit 

class ViewController: UIViewController{

    

    var count = 0

    // 第一次获取 view 属性时调用

    override func loadView() { 

        super.loadView()

        count+=1

        print("\(count)loadView") // 1

    } 

    override func viewDidLoad() {

        super.viewDidLoad()

        count+=1

        print("\(count)viewDidLoad") // 2

    } 

    override func viewWillAppear(_ animated: Bool) {

        super.viewWillAppear(animated)

        count+=1

        print("\(count)viewWillAppear") // 3

    }

    override func viewWillLayoutSubviews() {

        super.viewWillLayoutSubviews()

        count+=1

        print("\(count)viewWillLayoutSubviews") // 4

    }

    override func viewDidLayoutSubviews() {

        super.viewDidLayoutSubviews()

        count+=1

        print("\(count)viewDidLayoutSubviews") // 5

    }

    //这里才出现看到的东西

    override func viewDidAppear(_ animated: Bool) {

        super.viewDidAppear(animated)

        count+=1

        print("\(count)viewDidAppear") // 6 

    } 

    override func viewWillDisappear(_ animated: Bool) {

        super.viewWillDisappear(animated)

        count+=1

        print("\(count)viewWillDisappear") // 7

    }

    override func viewDidDisappear(_ animated: Bool) {

        super.viewDidDisappear(animated)

        count += 1

        print("\(count)viewDidDisappear") // 8

    } 

转载请注明原文地址: https://www.6miu.com/read-73.html

最新回复(0)