SwiftUI @EnvironmentObject error: may be missing as an ancestor of this view

后端 未结 3 731
Happy的楠姐
Happy的楠姐 2021-02-14 19:55

my first view can get all the data from API request, then opened second view to change the API request data, it crashed.

below is the error

Fatal error:          


        
3条回答
  •  花落未央
    2021-02-14 20:27

    if you are using sheet ore navigation you have to pass the environment Object maybe its a bug of swiftUI but it works for me in Xcode 11.5:

    .sheet(isPresented: $show){
            mySheetView().environmentObject(self.myEnviromentObject)
    }
    

提交回复
热议问题