'How to pass binding objects in other views?
I'm trying to pass textField values from one view to another, from AdressView to ShoppingView
struct AdressView: View {
@State var city = ""
@State var adress = ""
@State var houseNumber = ""
@State var flatNumber = ""
var body: some View {
NavigationLink(destination: ShoppingView(city: $city, adress: $adress, houseNumber: $houseNumber, flatNumber: $flatNumber)) {
Button {
} label: {
Text("Save")
.padding()
.foregroundColor(Color.blue)
}
}
struct ShoppingView: View {
@Binding var city: String
@Binding var adress: String
@Binding var houseNumber: String
@Binding var flatNumber: String
HStack {
Text("City:")
Spacer()
Text(city)
}
}
The problem is that ShoppingView is one of the tab items and I can't understand how I should pass binding objects of ShoppingView in MainView. I declared
@State var city = ""
@State var adress = ""
@State var houseNumber = ""
@State var flatNumber = ""
ShoppingView(city: $city, adress: $adress, houseNumber: $houseNumber, flatNumber: $flatNumber)
.tabItem {
Text("Cart")
Image(systemImage: "cart")
}
But this's not showing in ShoppingView any textField values, which I entered in AdressView.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
