【发布时间】:2020-08-21 08:01:13
【问题描述】:
我在表单中使用分段选择器来回答简单的“是”和“否”问题。分段选择器初始状态是否可以设置为 nil,以便在出现时既不突出显示/选择是或否?
@State private var equipmentCheck = 0
private var answers = ["Yes", "No"]
var body: some View {
NavigationView {
Form {
Section(header: Text("Questions")) {
Text("Have the plant and equipment been checked?")
Picker("", selection: $equipmentCheck) {
ForEach(0 ..< answers.count, id: \.self) {
Text("\(self.answers[$0])")
}
}
.pickerStyle(SegmentedPickerStyle())
.padding()
}
}
}
}
【问题讨论】:
-
我对@987654322@ 没有太多经验,但我看到您正在自己设置选择器的标签。为什么不根据
equipmentCheck自定义ForEach块中的Text。现在,您必须记住,Picker现在有三个统计信息 -none, yes , no。