Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift - func viewWillAppear

Tags:

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?

like image 752
Cristian C. Avatar asked Aug 19 '14 20:08

Cristian C.


People also ask

What is viewWillAppear in Swift?

Notifies the view controller that its view is about to be added to a view hierarchy.

How many times is viewWillAppear called?

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.

What triggers viewWillAppear?

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.

What is the difference between viewDidLoad and viewWillAppear?

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.


1 Answers

If you want to call viewWillAppear in swift use this.

override func viewWillAppear(_ animated: Bool) {     super.viewWillAppear(animated) // No need for semicolon } 
like image 156
iDev Avatar answered Nov 29 '22 07:11

iDev