在此代码中,编辑按钮按预期显示模式窗口。解雇时,界面不接受进一步的输入。换句话说,它只工作一次。这是SwiftUI中的另一个错误吗?
import SwiftUI
struct ContentView: View {
@State var showModal:Bool = false
var body: some View {
NavigationView{
Text("Sample")
.navigationBarTitle("List")
.navigationBarItems(leading:Button("Edit"){
self.showModal = true
})
}.sheet(isPresented: self.$showModal) {
Modal(isOn: self.$showModal)
}
}
}
struct Modal: View {
@Binding var isOn:Bool
var body: some View {
Text("Dismiss Modal View").onTapGesture {
self.isOn = false
}
}
}