【发布时间】:2019-10-29 11:35:14
【问题描述】:
好的-
我想要一个选择器视图来选择一个运算符:“=","" 此运算符将作为绑定发送:
@Binding var op:String
我的选择器:
Picker(selection: binding, label: Text("Query Type")) {
ForEach(0..<self.operators.count) { index in
Text(self.operators[index]).tag(index)
}
}.pickerStyle(SegmentedPickerStyle())
.padding()
现在我与回调的绑定:
let binding = Binding<Int>(
get: {
return self.pickerSelection
},
set: {
//pickerSelection = $0
print("SETTTING: \($0)")
self.op = self.operators[self.pickerSelection]
self.queryCallback()
})
所以,我可以完美地设置选择器。但是,当我回去编辑我的数据时,选择器永远不能选择现有的绑定运算符,比如“
我在 init 中添加了一个:
pickerSelection = operator.firstIndex(opValue)
但是这只会启动一个无限循环,因为 pickerSelection 是一个 @State 变量
谁有解决办法?
【问题讨论】:
标签: swiftui picker pickerview