我试图将值从第一个视图中的文本框传递到第二个视图中的文本框.
struct FirstView: View {
@State private var inputTextValue = ""
var body: some View {
NavigationView{
VStack {
TextField("",text: $inputTextValue)
.frame(width: 200, height: 30, alignment: .center)
.border(.gray)
NavigationLink(destination: {SecondView(incomingTextFieldvalue: inputTextValue)}, label: {Text("To second view")})
}
}
}
struct SecondView: View {
var incomingTextFieldvalue: String
@State var textFieldValue = "Initial Value in view 2"
var body: some View {
VStack {
Spacer()
TextField("",text: $textFieldValue)
.frame(width: 200, height: 30, alignment: .center)
.border(.gray)
Spacer()
Text("Incoming value: \(incomingTextFieldvalue)")
Text("This value: \(textFieldValue)")
Spacer()
}
}
所以,我想要的是,第二个视图中的文本框最初填充了传递的值.
我try 了各种解决方案,但都没有得到我需要的解决方案.如果我需要提供更多信息,请告诉我.