我想将两个唯一的警报附加到同一Button
视图。当我使用下面的代码时,只有底部的警报起作用。
我正在macOS Catalina上使用Xcode 11的正式版本。
@State private var showFirstAlert = false
@State private var showSecondAlert = false
Button(action: {
if Bool.random() {
showFirstAlert = true
} else {
showSecondAlert = true
}
}) {
Text("Show random alert")
}
.alert(isPresented: $showFirstAlert) {
// This alert never shows
Alert(title: Text("First Alert"), message: Text("This is the first alert"))
}
.alert(isPresented: $showSecondAlert) {
// This alert does show
Alert(title: Text("Second Alert"), message: Text("This is the second alert"))
}
Run Code Online (Sandbox Code Playgroud)
我希望在设置showFirstAlert
为true 时显示第一个警报,而在我设置为true时希望显示第二个警报showSecondAlert …