I have a standard SingleViewApplication
project.
ViewController.swift
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. println("viewDidLoad"); } }
When I start the application, viewDidLoad is called.
My scenario:
- press Home button (applicationDidEnterBackground
)
- recall application (applicationWillEnterForeground
)
and viewDidLoad
is not called.
Is there another func to override?
Notifies the view controller that its view is about to be added to a view hierarchy.
If both these methods are called, what's the difference between the two? viewDidLoad() is only called once, when the view is loaded from a . storyboard file. viewWillAppear(_:) is called every time the view appears.
The method viewWillAppear: is triggered in response to a change in the state of the application, indicating that the view controller is becoming “active.” The reason viewDidLoad exists – the only reason – is that it sometimes isn't possible or efficient to configure 100% of an interface in a XIB.
The difference between viewDidAppear and viewDidLoad is that viewDidAppear is called every time you land on the screen while viewDidLoad is only called once which is when the app loads.
If you want to call viewWillAppear
in swift use this.
override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) // No need for semicolon }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With