viewDidLoad
、viewWillAppear
、viewDidAppear
… 啊!這些到底是什麼啊?看着都暈了!不過沒關係,只要我們看看通過Swift代碼撰寫的例子,一定很快就能明白這一系列ViewController事件的發生順序啦~
先用視頻來看看準確順序
viewDidLoad
View 被載入時:
override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. println("viewDidLoad") }
viewWillAppear
View 要被呈現前,發生於 viewDidLoad 之後:
override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) println("viewWillAppear") }
viewDidAppear
View 呈現後,發生於 viewWillAppear 之後:
override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) println("viewDidAppear") }
viewWillDisappear
View 要結束前,要切換到下一個 View 時會發生此事件:
override func viewWillDisappear(animated: Bool) { super.viewWillDisappear(animated) println("viewWillDisappear") }
viewDidDisappear
View 完全結束後,發生於 viewWillDisappear 之後:
override func viewDidDisappear(animated: Bool) { super.viewDidDisappear(animated) println("viewDidDisappear") }