我想将关闭数据传递presentViewController
到上一个屏幕。在这里,我想使用块将数据作为 UIKitApp 传递到上一个屏幕。但我不知道传递数据。我们options
必须将数据传递回什么?
struct ContentView: View {
@State var showModel = false
var body: some View {
VStack {
Button(action: {
showModel.toggle()
}, label: {
Text("Show filters")
}).sheet(isPresented: $showModel, content: {
FilterView()
})
}
}
}
struct FilterView: View {
@Environment(\.presentationMode) var presentationMode
var onDismiss: ((_ model: Filter) -> Void)?
var body: some View {
VStack {
Button(action: {
// Pass data from here to ContentView
let filter = Filter(fromDate: "10/07/2021", toDate: "12/07/2021")
onDismiss?(filter)
presentationMode.wrappedValue.dismiss()
}, label: {
Text("Applay Filters")
}).padding()
}.padding()
}
}
struct Filter {
var fromDate: String
var toDate: String
}