有没有人有解决以下崩溃的方法?
我有一个通过 NavigationLink 在父导航控制器中显示的表单,如下所示:
var body: some View {
NavigationView {
NavigationLink(destination: PickerView()) {
Text("Picker View")
}
}
}
Run Code Online (Sandbox Code Playgroud)
PickerView 有三个选择器。第一个确定显示其他哪些:
struct PickerView: View {
@State var sectionValue = "pet"
@State var petValue = "dog"
@State var fruitValue = "apple"
@State var foodValue = "pasta"
var body: some View {
Form {
Picker(selection: $sectionValue, label: Text("What is your favorite?")) {
Text("Pet").tag("pet")
Text("Fruits").tag("fruits")
Text("Foods").tag("foods")
}
if (sectionValue == "pet") {
Picker(selection: $petValue, label: Text("Favorite pet")) {
Text("Dog").tag("dog")
Text("Cat").tag("cat")
Text("Lizard").tag("lizard")
}
} …Run Code Online (Sandbox Code Playgroud)