In SwiftUI I'm trying to make an alert message with input, and then get the value from the input. I've found many good tutorials how to make the Alert View in SwiftUI, but dont found how to add TextField() in Alert. This alert will update Categories table on Server, i will call a put request with this alert.
@State var isInsertAlertVisible = false
// state var is define in ContentView
// Button is define in body
Button(action: {
self.isInsertAlertVisible = true
}
,
label: {
Text("Create")
.multilineTextAlignment(.center)
.foregroundColor(Color.white)
})
.presentation($isInsertAlertVisible) {
Alert(title: Text("Insert"), message:
Text("Insert Categories"), dismissButton: .default(Text("OK!")){
print("Got it")
})
}
.padding(.all)
.background(Color.blue)
来源:https://stackoverflow.com/questions/57148220/swiftui-present-alert-with-input-field