我正在使用Swift 3.
这是代码:
public func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if (selectedstatename == nil) {
return dataList.count
} else {
return dataList1.count
}
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if (selectedstatename == nil) {
return dataList[row].title
} else {
return dataList1[row].dist
}
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if (selectedstatename == nil) {
cityField.text = dataList[row].title
selectedstatename = cityField.text
self.pickerView.reloadAllComponents()
cityField.resignFirstResponder()
} else {
self.pickerView.reloadAllComponents()
cat.text = dataList1[row].dist
cat.resignFirstResponder()
}
}