5

下面的代码正在运行(onAppear 被调用)但是一旦我将两个视图嵌套在 tabView 中(以呈现类似 UIPageViewController 的 UI),第二个视图的 onAppear 函数就永远不会被调用,这是一个错误还是我的什么做错了吗?

struct SetUpWorkoutView: View {
        
        var body: some View {
            NavigationView {
                List {
                    ForEach(sessionTypes) { sessionType  in
                    NavigationLink(destination: LiveWorkoutView(sessionType: sessionType)) {
                        SessionTypeRow(name: sessionType.stringValue)
                    }
                }
            }
        }


 struct LiveWorkoutView: View {
     var body: some View {
    VStack(alignment: .leading) { }
      }.onAppear(perform: {
                    print("on appear called in LiveWorkoutView")
      }
    }
   }
}

@main
struct SwiftUITestApp: App {

    var body: some Scene {
        WindowGroup {
            TabView {
                SetUpWorkoutView()
                WatchSettingsView()
            }
            .tabViewStyle(PageTabViewStyle())
        }
    }
}
4

0 回答 0