-1

我认为是这样的情况,指定为环境对象的类中的@Published 属性会自动更新到我将环境对象传递给的所有子视图,但是下面的代码没有更新,我做错了什么?

class trackerDataStore: ObservableObject {
    
    let healthStore = HKHealthStore()
    
    @Published var isLoadingWorkouts = false
    @Published var subscriptionIsActive = false
    @Published var trackerWorkoutObject: trackerWorkoutObject?
    
}
    

struct detailHeaderCard: View {
    
    @EnvironmentObject var trackerDataStore: TrackerDataStore
    
    var body: some View {
        //omitted
    }
    .sheet(isPresented: $isShowingPlayerAddStatsFormAsModal) {
        PlayerAddStatsForm(isShowingPlayerAddStatsFormAsModal: $isShowingPlayerAddStatsFormAsModal)
            .environmentObject(trackerDataStore)
    }
    
}
   
 
struct PlayerAddStatsForm: View {
    
    @EnvironmentObject var trackerDataStore: TrackerDataStore
    //not getting reactively updated here

}
4

1 回答 1

0

我发现我的连接方式@EnvironmentObject实际上运行良好,我在另一个区域的代码中有一个错误,它阻止视图接收我正在寻找的数据,这让我认为它与@EnvironmentObject无法正常工作有关。

于 2020-10-27T13:15:25.043 回答