如何从字典中填充UIPickeView?

时间:2017-06-25 13:04:49

标签: ios swift dictionary uipickerview

我有这个pickerData:

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,但是在这个键中,我总是得到第一个元素,因为每次这个块一次又一次地调用。

如何解决我的问题?

1 个答案:

答案 0 :(得分:1)

您正在使用字典,因此您不能只为其提供索引。冷杉

sudo apt install libpq-dev python-dev