I'm trying to have the selected item in the Picker display at the top of the view. I have added. standard picker:
Section(){ Picker(selection: $selectedYear, label: Text("")) { ForEach(2000...2050, id: .self) { Text(String($0)) } } }
2020 is currently selected, however when the view appears it displays from 2000 at the top, 2020 outside of the screen with a check next to it.
Pickers in SwiftUI need a tag to work.
Section(){ Picker(selection: $selectedYear, label: Text("")) { ForEach(2000...2050, id: .self) { Text(String($0)).tag($0) // <= add this to work } } }
2.1m questions
2.1m answers
60 comments
57.0k users