我目前正在使用 Swift 开发一个应用程序,其中我使用 UIPickerView。我想在pickerView(myPickerView)中设置值
let PickerData = {
"listOfGrouoc": {
"1": "DDDDD",
"2": "SDDDDD",
"3": "TTTT"
},
"TypeOfGrpos": [
"STTTTT",
"TTTTT"
],
"SubTypp": {
"3": "Shh",
"6": "SSS",
"9": " dfdf"
"14": "Shh",
"21": "SSS",
"60": " dfdf"
},
"GropName": {
"1": "test",
"2": "test"
}
}
这是来自服务器的响应我想在pickerView中显示组listOfGrouoc
下面的代码: -
在viewDidLoad
我有:
Picker.delegate = self
Picker.dataSource = self
然后我有所需的方法:
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return PickerData.count
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return PickerData[row] trying to show SSSSS,DDDDD,GGGGG
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
print(PickerData[row]) expecting only id Int Value
}
问题:- 有人可以向我解释如何在选择器视图标题中设置 dict 值以及单击 didSelectRow 时获取 dict key 。任何帮助将不胜感激。
提前致谢。