我的应用程序中有一个“与我们联系”页面,其中包含4个不同的区域。在每个区域下,我都有一个下拉菜单,其中将每个联系人的姓名填充到UIPickerview中。所有4个下拉列表均填充JSON数据中的所有名称。我要对每个区域进行检查,以检查其ID是否等于该区域的人的ID,然后仅显示这些名称。目前,这是我正在使用的代码。如何检查特定ID?
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if pickerView == thePicker {
return contactUsInfo.count
}
else if pickerView == thePicker2 {
return contactUsInfo.count
}
else if pickerView == thePicker3 {
return contactUsInfo.count
}
else if pickerView == thePicker4 {
return contactUsInfo.count
}
return 1
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if pickerView == thePicker {
return contactUsInfo[row].fullName
}
else if pickerView == thePicker2 {
return contactUsInfo[row].fullName
}
else if pickerView == thePicker3 {
return contactUsInfo[row].fullName
}
else if pickerView == thePicker4 {
return contactUsInfo[row].fullName
}
return ""
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if (pickerView == thePicker) {
self.DropdownField.text = self.contactUsInfo[row].fullName
}
else if (pickerView == thePicker2) {
self.DropdownField2.text = self.contactUsInfo[row].fullName
} else if (pickerView == thePicker3) {
self.DropdownField3.text = self.contactUsInfo[row].fullName
} else if (pickerView == thePicker4) {
self.DropdownField4.text = self.contactUsInfo[row].fullName
}
}
我对此的想法是
var id = contactUsInfo.id
if contactUsInfo.id == (id: 1, id: 2, id: 3, etc) {
pickerview == thePicker {
return contacUsInfo[row].fullName
}
} else if if contactUsInfo.id == (id: 4, id: 5, id: 6, etc) {
pickerview == thePicker2 {
return contacUsInfo[row].fullName
}
}
我知道此代码不正确,这就是我正在寻找的答案。