[英]viewDidLoad() and viewDidAppear() called only once?
This is my ViewController (no changes to other files):这是我的 ViewController(对其他文件没有更改):
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("hi from vdl")
}
override func viewDidAppear(_ animated: Bool) {
print("hi from vda")
}
}
hi from vdl
来自vdl的你好
hi from vda你好来自vda
Message from debugger: Terminated due to signal 9
来自调试器的消息:由于信号 9 而终止
When you close the app in simulator, you break the connection with the debugger.当您在模拟器中关闭应用程序时,您会断开与调试器的连接。
PS You didn't call super
in viewDidAppear
. PS您没有在
viewDidAppear
中调用super
。
viewDidLoad()
and viewDidAppear()
work when you get in a VC(ViewController),like present,push,pop,dismiss. viewDidLoad()
和viewDidAppear()
在你进入 VC(ViewController) 时工作,比如 present、push、pop、dismiss。
When a VC is presented or pushed to other VC, viewDidLoad()
and viewDidAppear()
will work.And when you pop/dismiss a VC,the previous VC shows up which make viewDidAppear()
work.当一个 VC 被呈现或推送到其他 VC 时,
viewDidLoad()
和viewDidAppear()
将起作用。当你弹出/关闭一个 VC 时,前一个 VC 会出现,这使得viewDidAppear()
起作用。
But Move to home screen doesn't make effect on the two.但是移动到主屏幕不会对两者产生影响。
If you want to know when the app will enter the background,use the func applicationDidEnterBackground(_ application: UIApplication)
in AppDelegate.swift
如果您想知道应用程序何时进入后台,请使用
AppDelegate.swift
中的func applicationDidEnterBackground(_ application: UIApplication)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.