このような 3 つのピッカーがあります。1 つ目は generalPicker で、2 つ目と 3 つ目は同じです。generalPicker には、["Length", "Volume", "Mass"] という配列 (メニュー) があり、たとえば generalPicker の Mass など、選択するたびに、2 番目と 3 番目のピッカーに入りたいと考えています。この配列: ["Milligram", "Centigram", "Gram", "Kilogram", "Stone", "Pound", "Ounce"].
または、generalPicker で長さを選択した場合、2 番目と 3 番目のピッカーを取得したい: ["Millimeter", "Centimeter", "Meter", "Kilometer", "Foot", "Yard" 、「マイル」]。
誰かが実際にそれを行う方法を教えてもらえますか? 私のコードのサンプル(ピッカー構成):
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"]