我有这个选择器数据:
var pickerData: (id: String, value: [String: String])?
当我点击UITextField时,我会执行下一步:
@IBAction func whoCanSee(_ sender: UITextField) {
pickerData = (id: "viewOption", value: ["F": "Me and my friends", "M": "Only certain users", "E": "Every user"])
sender.inputView = self.pickerView
}
后来
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int)
我正在尝试从元组中的
value
获取值:self.pickerData!.value.values[row]
但它返回给我一个错误:
Cannot subscript a value of type 'LazyMapCollection<Dictionary<String, String>, String>' with an index of type 'Int'
我也尝试过使用
for...in
但是在这个键中,显然我总是得到第一个元素,因为每次这个块一次又一次调用。我怎样才能解决我的问题?
最佳答案
你在用字典,所以你不能给它一个索引。冷杉
let arr = Array(self.pickerData!.value)
print(arr[row])
关于ios - 如何从字典填充UIPickeView?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44746642/