【发布时间】:2020-07-04 22:06:42
【问题描述】:
以下代码仅显示错误警报。有没有办法让警报匹配 IF 条件?
@State var showTrueAlert = false
@State var showFalseAlert = false
var body: some View {
Button(action: {
let isTrue = Bool.random()
if isTrue {
self.showTrueAlert = true
print("True Alert")
} else {
self.showFalseAlert = true
print("False Alert")
}
}) {
Text("Random Alert")
.font(.largeTitle)
}
.alert(isPresented: $showTrueAlert) {
Alert(title: Text("True"))
}
.alert(isPresented: $showFalseAlert) {
Alert(title: Text("False"))
}
}
【问题讨论】:
-
是的。这些链接非常有用。谢谢
标签: swiftui