Hi, I have this issue where I have this code and when I arrange the .alerts in any way, none of them show except the codeError alert. Please Help!
Multiple Alerts not showing
Why do you stack alerts this way ? What do you expect ? Only the last may eventually be displayed, depending on its isPresented value.
.alert(isPresented: $codeExists, content: { }
We see where state vars are set to false. But where are they set to true ? You do not show code.
Here is the entire file:
Thanks. I checked for codeExists. It is never set true:
declared false
@State private var codeExists = false
set false in setup
func setup() {
if picktType == .media {
codeExists = false
// …
} else {
codeExists = false
And used in alert and set false again
.alert(isPresented: $codeExists, content: {
Alert(title: Text("Error"), message: Text("Please try again"), dismissButton: .default(Text("Ok"), action: {
codeExists = false
creating = false
}))
})
So alert can never be triggered.
And once again, stacking alert call
.alert {
}
.alert {
}
visibly doesn't work.
Ok, thx. Code exists is legacy and from a much earlier version. I will take it out. However, if I move
.alert(isPresented: $disabledAlert, content: {
Alert(title: Text("Network Error"), message: Text("You aren't connected to the internet, please connect to use Pickt."), dismissButton: .default(Text("Ok"), action: {
disabledAlert = false
presentationMode.wrappedValue.dismiss()
}))
})
to be a child of
AlertControlView(textString: $blank, showAlert: $enterLoc, textPlaceholder: $textAlertFieldPlaceholder, title: "Error", message: "Please enter location to continue.", onDone: { loc in
location = loc
create()
}, onCancel: {
enterLoc = false
creating = false
})