View Controller Lifecycle

A view controller has a series of “lifecycle” methods that are called at various stages. When the view controller is initially set up, viewDidLoad is called. As it is shown and hidden, viewWillAppear, viewDidAppear, viewWillDisappear, and viewDidDisappear will be called. The appearance and disappearance are split into two methods because sometimes you want some behavior to happen before the transition animation starts or after the transition animation ends.

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
println("view will appear")
}

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
println("view did appear")
}

override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
println("view will disappear")
}

override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
println("view did disappear")
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s