相信大家在初初开始进行iOS编程时,都曾被各种 viewDidLoad
、 viewWillAppear
、 viewDidAppear
等各种各样的事件Func弄得头晕眼花,所以今天「畅想资源」就来举几个例子来让大家可以对这些ViewController上不同的事件更为了解!(附Swift程式码)
影片预览
viewDidLoad
View 被载入时:
1 2 3 4 5 6 |
override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. println("viewDidLoad") } |
viewWillAppear
View 要被呈现前,发生于 viewDidLoad 之后:
1 2 3 4 5 |
override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) println("viewWillAppear") } |
viewDidAppear
View 呈现后,发生于 viewWillAppear 之后:
1 2 3 4 5 |
override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) println("viewDidAppear") } |
viewWillDisappear
View 要结束前,要切换到下一个 View 时会发生此事件:
1 2 3 4 5 |
override func viewWillDisappear(animated: Bool) { super.viewWillDisappear(animated) println("viewWillDisappear") } |
viewDidDisappear
View 完全结束后,发生于 viewWillDisappear 之后:
1 2 3 4 5 |
override func viewDidDisappear(animated: Bool) { super.viewDidDisappear(animated) println("viewDidDisappear") } |