10

I am playing around with SwiftUI, and am currently building a Form using a Picker.

import SwiftUI

struct ContentView: View {
  private let names = ["Bill", "Peter", "Johan", "Kevin"]
  @State private var favoritePerson = "Bill"

  var body: some View {
    NavigationView {
      Form {
        Picker("Favorite person", selection: $favoritePerson) {
          ForEach(names, id: \.self) { name in
            Text(name)
          }
        }
      }
      .navigationBarTitle("Form", displayMode: .inline)
    }
  }
}

The first time you tap on the "Favorite person" row, the picker shows up fine, and tapping on one of the names brings you back to the form. But tapping on the form row a second time doesn't do anything: you don't go to the picker, the row stays highlighted but nothing happens. If this is a SwiftUI bug, is there a known workaround? (I already needed to use a small navigation bar title to work around the Picker UI bug where otherwise its content moves up when it's shown ☹️)

Kevin Renskers
  • 5,156
  • 4
  • 47
  • 95
  • Works fine with Xcode 11.2. If you use 11.3, just downgrade. – Asperi Jan 01 '20 at 14:21
  • Isn't that just going to reintroduce a bunch of other bugs though? (Also, come on Apple! Ugh..) – Kevin Renskers Jan 01 '20 at 14:33
  • As far as I observe 11.3 introduced just huge amount of broken areas, and 11.1 was most stable. – Asperi Jan 01 '20 at 14:37
  • Don't think this is limited to Form / Picker. I seem to get this with a simple NavigationLink whereby the initial tap works all fine but subsequent taps do nothing e.g. struct ContentView: View { var body: some View { NavigationView { Section { NavigationLink(destination: Text("Hello")) { Text("Tap me...") } } .navigationBarTitle("Demo") } } } I'm using Xcode 11.3 – sukh Jan 06 '20 at 23:05

2 Answers2

7

this issue is just one with the simulator. If you build the app on a physical iOS device, it no longer becomes an issue. It's like that bug with Navigation Link that would only work once.

Tahmid Azam
  • 566
  • 4
  • 16
1

I have the same problem in Xcode 11.4 and also in the real device. Picker change didn't call CreateTab, it only worked in initialize.

Picker("Numbers", selection: $selectorIndex) {
            ForEach(0 ..< formData.tabs.count) { index in
                Text(formData.tabs[index].name).tag(index)
            }
          }
          .pickerStyle(SegmentedPickerStyle())
          .onReceive([self.selectorIndex].publisher.first()) { (value) in
            print(value)
            CreateTab(tabs: formData.tabs, index: self.selectorIndex)
}
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Ali Tavakoli
  • 71
  • 1
  • 3