我有 3 个这样的选择器:第一个是 generalPicker,第二个和第三个是一样的。在 generalPicker 中,我有一个数组(菜单):[“Length”,“Volume”,“Mass”] 每次我想选择,例如来自 generalPicker 的 Mass,我想进入第二个和第三个选择器这个数组:["毫克"、"厘克"、"克"、"千克"、"石"、"磅"、"盎司"]。
或者,如果我在 generalPicker 中选择,比如说长度,那么我想进入第 2 和第 3 选择器:[“毫米”、“厘米”、“米”、“公里”、“英尺”、“码” , “英里”]。
谁能给我一个想法,我该怎么做?我的代码示例(选择器配置):
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if pickerView.tag == 0 || pickerView.tag == 1 {
return self.pickerLength.count
} else if pickerView.tag == 2 {
return self.pickerGeneral1.count
}
return 3
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if pickerView.tag == 0 || pickerView.tag == 1{
return self.pickerLength[row]
} else if pickerView.tag == 2 {
return self.pickerGeneral1[row]
}
return ""
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if pickerView.tag == 0 {
self.pickerTextField.text = self.pickerLength[row]
self.view.endEditing(true)
}else if pickerView.tag == 1 {
self.pickedTextField2.text = self.pickerLength[row]
self.view.endEditing(true)
}else if pickerView.tag == 2 {
self.pickerGeneral.text = self.pickerGeneral1[row]
self.view.endEditing(true)
}
}
数组定义:
private var pickerMass = ["Milligram", "Centigram", "Gram", "Kilogram", "Stone", "Pound", "Ounce"]
private var pickerVolume = ["Milliliter", "Centiliter", "Liter", "Gallon", "Quart", "Pint", "Fluid ounce"]
private var pickerLength = ["Millimeter", "Centimeter", "Meter", "Kilometer", "Foot", "Yard", "Mile"]
private var pickerGeneral1 = ["Length", "Volume", "Mass"]