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())
}
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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.