1

I don't know why the picker is not working inside of a form in Swift UI. The app will be crashing if the user is going to tap for the second time. The console will print the following output:

[TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window).


struct ContentView: View {

    @State private var countryIndex = 0

    var countries = ["US", "Germany", "Korea", "Russia"]

    var body: some View {

        NavigationView {

            Form {
                Section {
                    Picker(selection: $countryIndex, label: Text("Country")) {
                                   ForEach(0 ..< countries.count) {
                                       Text(self.countries[$0]).tag($0)
                                   }
                               }

                }
                .navigationBarTitle(Text("Country"))
            }


        }
    }
}
Dhaval Raval
  • 594
  • 2
  • 7
Niels
  • 375
  • 5
  • 15
  • Does this answer your question? [Why is SwiftUI picker in form repositioning after navigation?](https://stackoverflow.com/questions/58773687/why-is-swiftui-picker-in-form-repositioning-after-navigation) – AnupamChugh Jan 30 '20 at 17:04

1 Answers1

0

First, the warning you get is just a warning, so you shouldn't mind, but if you set .navigationBarTitle("xyz", displayMode: .inline), it'll go away.

Second, the navigation only working once is an issue only in simulator, if you build and run on a real device, it won't happen.

iSpain17
  • 2,502
  • 3
  • 17
  • 26