我想制作一个应用程序,用户按下一个按钮,然后当他们选择一个选项时,会弹出另一个警报。当我尝试类似的事情时;
struct ContentView: View {
@State private var showingAlert = false
@State private var showingAlertII = false
var body: some View {
Button(action: {
self.showingAlert = true
}, label: {
Text("button")
.alert(isPresented: $showingAlert) {
Alert(title: Text("Option one or two"), message: Text("choose"), primaryButton: .default(Text("one"), action: {
// do some specific actions
self.showingAlertII = true
}), secondaryButton: .default(Text("two"), action: {
//do some other stuff
self.showingAlertII = true
}))
}
.alert(isPresented: $showingAlertII) {
Alert(title: Text("Option A or B"), message: Text("choose"), primaryButton: .default(Text("Split"), action: …Run Code Online (Sandbox Code Playgroud)