//环境对象类
class AppData: ObservableObject {
@Published var studs : [StudentModel]
}
var body: some View {
VStack{
List(appData.studs,id:\.rollNo){ s in //causing error
Text("\(s.rollNo)")
NavigationLink("", destination: StudentView(s: s))
}
}.navigationBarItems(trailing:
Button(action: {
self.addStud.toggle()
}){
Image(systemName: "plus")
.renderingMode(.original)
}
.sheet(isPresented: $addStud, content: {
AddStudent()
})
)
.navigationBarTitle(Text("Students"),displayMode: .inline)
}
致命错误:未找到 AppData 类型的 ObservableObject。AppData 的 View.environmentObject(_:) 作为此视图的祖先可能会丢失。