Using Keyboard Done/Enter button.
struct ContentView: View {
@State var myText = ""
var body: some View {
TextField("Protocole", text: $myText) { _ in } onCommit: {
print("done")
}
}
}
Using extra button.
struct ContentView: View {
@State var myText = ""
var body: some View {
TextField("Placeholder", text: $myText)
Button("Done") {
print("Done button pressed -> Text: (myText)")
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…