Post

Replies

Boosts

Views

Activity

Picker Label not showing anymore
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()) } }
15
1
8.7k
Aug ’21
Navigation Stack Management
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.
0
0
447
Oct ’20
How to make binding work properly
How do I make my @State value change when the picker changes? struct ContentView: View { &#9;&#9;@State var Choioce: Int? &#9;&#9;var settings = ["ch1", "ch2", "ch3"] &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;Picker("Options", selection: $Choioce) { &#9;&#9;&#9;&#9;&#9;&#9;Text("Please Select One") &#9;&#9;&#9;&#9;&#9;&#9;ForEach(0 ..< settings.count) { index in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(self.settings[index]) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.tag(index) &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;Text("You selected: \(settings[Choioce!])") &#9;&#9;} } The You selected text view never changes.
3
0
548
Aug ’20