在下面的代码中,无论我将第二个.actionSheet
附加到哪里,我都无法使它们工作.我的理解是,只要他们持有不同的观点,就会奏效,但这一理论似乎并不正确.
struct ContentView: View {
@State private var showFirstActionSheet = false
@State private var showSecondActionSheet = false
var body: some View {
VStack{
VStack{
Button("Show Fist Action Sheet"){
showFirstActionSheet = true
}
.actionSheet(isPresented: $showFirstActionSheet) {
ActionSheet(title: Text("First Action Sheet"), message:
Text("Some message!"),
buttons: [
.destructive(Text("Cancel")){
},
.default(Text("Yes")){
doSomething()
},
.cancel()
])
}
}
}
.actionSheet(isPresented: $showSecondActionSheet) {
ActionSheet(title: Text("Second Action Sheet"), message:
Text("Some message!"),
buttons: [
.destructive(Text("Cancel")){
},
.default(Text("Yes")){
},
.cancel()
])
}
}
func doSomething(){
showSecondActionSheet = true
}
}
我try 了两个不同的按钮,它的工作,但在我的情况下,我只有一个按钮,触发第一个和第二个是由第一个actionSheet触发.
你知道处理这件事最好的办法是什么吗?