@Jonathan didn't pick the right option!
What gives?
When I click on select a student it gives me a drop down of all the students
it does not go to the navigation view with the back button.
Evolution
You've witnessed the constant evolution of SwiftUI! It's changing at a breath-taking pace. Buckle up! The Apple World Wide Developer's Conference is next month, and there will surely be big changes. You're in the right place to learn. @twoStraws stays up late into the night to create Playgrounds demonstrating the newest cutting edge features in the language.
Picker Styles
What you see in the video (published ages ago in October 2021!) was the default behaviour of a Picker
component in SwiftUI. You'd wrap the Picker
in a NavigationView
and when you tapped the names, SwiftUI would navigate to a second screen displaying your options, and an optional back button. When you tapped a name, you'd return to the starting screen.
Later, SwiftUI was updated allowing you to select from several pickerStyles
! Nice! The code snip below shows several of the available styles. Uncomment them one at a time to see their effect on the picker. Please return here and tell us which one you prefer and why!
Picker("Select your student", selection: $selectedStudent)
{
ForEach(students, id: \.self)
{
Text($0)
}
}
// Picker objects have several optional styles!
// Uncomment one at a time and try it out.
// .pickerStyle(.inline)
// .pickerStyle(.segmented)
// .pickerStyle(.menu)
.pickerStyle(.navigationLink) // <-- old default picker style
Keep coding!