import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
// Dispose of any resources that can be recreated.
}
//////////////////////////////////////////////////////////////////////
override func loadView() {
super.loadView()
print( object_getClass(self), "-->", #function )
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
print( object_getClass(self), "-->", #function )
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
print( object_getClass(self), "-->", #function )
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
print( object_getClass(self), "-->", #function )
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
print( object_getClass(self), "-->", #function )
}
override func viewWillDisappear(_ animated: Bool) {
super.viewDidAppear(animated)
print( object_getClass(self), "-->", #function )
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidAppear(animated)
print( object_getClass(self), "-->", #function )
}
//////////////////////////////////////////////////////////////////////
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()// Dispose of any resources that can be recreated.
}
//////////////////////////////////////////////////////////////////////
override func loadView() {
super.loadView()
print( object_getClass(self), "-->", #function )
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
print( object_getClass(self), "-->", #function )
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
print( object_getClass(self), "-->", #function )
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
print( object_getClass(self), "-->", #function )
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
print( object_getClass(self), "-->", #function )
}
override func viewWillDisappear(_ animated: Bool) {
super.viewDidAppear(animated)
print( object_getClass(self), "-->", #function )
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidAppear(animated)
print( object_getClass(self), "-->", #function )
}
//////////////////////////////////////////////////////////////////////
}
本文介绍了一个SwiftUI应用程序中ViewController类的实现,详细展示了视图控制器从加载到消失各个阶段的方法覆盖与使用,这对于理解SwiftUI中视图生命周期非常重要。
1147

被折叠的 条评论
为什么被折叠?



