SwiftUI -> Thread 1: Fatal error: No observable object of type MyObject.Type found (EnvironmentObject in sheet)

前端 未结 1 1083
慢半拍i
慢半拍i 2021-01-30 20:42

I\'m building an app with SwiftUI. When I was trying to display a sheet (previously Modal), this error message appears:

Thread 1: Fatal error: No observable objec         


        
相关标签:
1条回答
  • 2021-01-30 21:15

    You have to pass your environment object to BixiStationDetailView, otherwise it won't have anything to bind to its @EnvironmentObject.

    .sheet(isPresented: self.$isModalOpen) {
        BixiStationDetailView(station: self.station)
            .environmentObject(self.bixiModel)
    }
    

    Since you're presenting BixiStationDetailView as a sheet, it isn't a subview of your CardView and therefore doesn't inherit its @EnvironmentObject.

    0 讨论(0)
提交回复
热议问题