I have a standard textfield connected to one State property. and it does not allow me to type text into the field in the full simulator but it works in the live preview section.
Is this a bug?
Post
Replies
Boosts
Views
Activity
How do I make my @State value change when the picker changes?
struct ContentView: View {
		@State var Choioce: Int?
		var settings = ["ch1", "ch2", "ch3"]
		var body: some View {
				Picker("Options", selection: $Choioce) {
						Text("Please Select One")
						ForEach(0 ..< settings.count) { index in
								Text(self.settings[index])
										.tag(index)
						}
				}
		Text("You selected: \(settings[Choioce!])")
		}
}
The You selected text view never changes.
struct Testing: View {
@EnvironmentObject var navHelp : NavigationHelper
var body: some View {
NavigationView {
VStack {
NavigationLink(destination:testing2(),
tag : "testing2",
selection : $navHelp.selection)
{ Text("Go to two") }
}
.navigationBarTitle("Navigation")
}
}
}
struct testing2 : View {
@EnvironmentObject var navHelp : NavigationHelper
var body: some View{
VStack {
NavigationLink(destination:testing3(),
tag : "testing3",
selection : $navHelp.selection)
{ Text("Go to 2n3") }
}
.navigationBarTitle("Second Page")
}
}
struct testing3 : View {
@EnvironmentObject var navHelp: NavigationHelper
var body: some View{
VStack {
Button(action: {
navHelp.selection = "testing2"
}, label: {
Text("Go to two")
})
}
.navigationBarTitle("Third Page")
}
}
class NavigationHelper: ObservableObject {
@Published var selection: String? = nil
}
I am trying to navigate to any page inside of my NavigationView. I made an ObservableObject and passed it in as an EnvironmentObject. I found a similar answer on stack about this.
I can get it to work to returning to the first page by setting the value to nil or the second page by setting the selection to testing2.
How do I get it to work with another layer? When I add a new tagged NavigationLink the NavigationView automatically goes back to the top of the stack.
The Label for Picker is not being displayed anymore is there a way to fix this? The label used to show in earlier versions instead of the first option.
struct ExampleView: View {
var fruits = ["Banana","Apple", "Peach", "Watermelon", "Grapes" ]
@State private var selectedFruit = 0
var body: some View {
VStack {
Picker(selection: $selectedFruit, label: Text("Select Favorite Fruit")) {
ForEach(0..<fruits.count) {
Text(self.fruits[$0])
}
}
Text("Your Favorite Fruit: \(self.fruits[selectedFruit])")
}
.pickerStyle(MenuPickerStyle())
}
}