我尝试过在分段和轮式选择器之间进行切换,但是在单击时均未注册选择。
NavigationView {
Form {
Picker(selection: self.$settings.senatorChoice, label: Text("Choose a senator")) {
ForEach(0 ..< self.customSenators.count) {
Text(self.customSenators[$0])
}
}.pickerStyle(WheelPickerStyle())
.labelsHidden()
.padding()
}
}
答案 0 :(得分:0)
为每个选择器项目添加一个标记,这样它们是唯一的,例如
Text(self.customSenators[$0]).tag($0)
答案 1 :(得分:0)
再次检查settings.senatorChoice
是Int
。 ForEach
中范围的类型必须与Picker
绑定的类型相匹配。 (有关更多信息,请参见here。
此外,您可能想使用ForEach(self.customSenators.indices, id: \.self)
。如果将元素添加到customSenators
或从var $x = 1; // Is this valid with the $ in front?
var y = 2; // This is valid JavaScript
中删除元素,这可以防止崩溃和过时的UI。 (有关更多信息,请参见here。)
答案 2 :(得分:0)
下面的测试代码在单击时注册选择。
key_ptr = ptr::null()