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
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.