Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我想加载数据以显示到 UI(例如 Twitter 的时间线),我将 API 调用的过程放在 viewDidLoad 中。但是,我在 Apple 教程中找不到类似于 viewDidLoad 的地方。
我应该将与 UI 无关的流程放在哪里?
SwiftUI 为我们提供了与 UIKit 的 viewDidAppear() 和 viewDidDisappear() 方法相同的方法,但它们的名称略有不同,即 onAppear() 和 onDisappear()。
struct DetailView : View { var body: some View { NavigationView { Text("Hello World") }.onAppear { // enter viewDidAppear() code here } } }