我有一个标准的SingleViewApplication项目。
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");
}
}启动应用程序时,将调用viewDidLoad。
我的场景:
applicationDidEnterBackground)applicationWillEnterForeground)
viewDidLoad也没有被调用。还有别的功能可以覆盖吗?
发布于 2014-10-28 12:54:34
如果您想快速调用viewWillAppear,请使用此命令。
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) // No need for semicolon
}发布于 2015-04-29 11:11:36
最佳实践是在您的UIApplicationWillEnterForegroundNotification和UIApplicationWillEnterBackgroundNotification中注册ViewController
public override func viewDidLoad()
{
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationWillEnterForeground:", name: UIApplicationWillEnterForegroundNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationWillEnterBackground:", name: UIApplicationDidEnterBackgroundNotification, object: nil)
}
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
func applicationWillEnterForeground(notification: NSNotification) {
println("did enter foreground")
}
func applicationWillEnterBackground(notification: NSNotification) {
println("did enter background")
}发布于 2014-08-19 20:33:28
根据诺亚的答复:
在ViewController.swift上添加刷新函数并从AppDelegate.swift > applicationWillEnterForeground调用它
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");
refresh();
}
func refresh(){
println("refresh");
}
}。
AppDelegate.swift
func applicationWillEnterForeground(application: UIApplication!) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
ViewController().refresh();
}输出:
viewDidLoad
refresh
refresh
refresh
refresh https://stackoverflow.com/questions/25392124
复制相似问题