Single picker view for several text field

Hi All

 

Im building an app that has 5 pickerview in total. i need one of the pickerview (tag 4) to allow the user to select items from the picker view for 8 seperate text fields. so, i need “case 4” in “didselectrow” to repeat if other textfield are selected and to place the selected row in the the text that did begin the picker.  here is my code..

 

let dropDown = UIPickerView()

    dropDown.tag = 1

 

    dropDown.dataSource = self

    dropDown.delegate = self

 

    let trafficHazardsPicker = UIPickerView()

    trafficHazardsPicker.tag = 2

 

    trafficHazardsPicker.dataSource = self

    trafficHazardsPicker.delegate = self

 

    let controlMethodPicker = UIPickerView()

    controlMethodPicker.tag = 3

 

    controlMethodPicker.dataSource = self

    controlMethodPicker.delegate = self

 

    let controlDetailsPicker = UIPickerView()

    controlDetailsPicker.tag = 4

 

    controlDetailsPicker.dataSource = self

    controlDetailsPicker.delegate = self

 

let matrixAfterPicker = UIPickerView()

    matrixAfterPicker.tag = 5

 

    matrixAfterPicker.dataSource = self

    matrixAfterPicker.delegate = self

 

func numberOfComponents(in pickerView: UIPickerView) -> Int {

   

            return 1

 

    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {

  

         switch pickerView.tag {

       

            case 1:

                return list.count

            case 2:

                return matrixList.count

            case 3:

                return controlMethodList.count

            case 4:

                return controlDetailsList.count

            case 5:

                return matrixList.count

       

            default:

                return 1

           

        }

    }

 

 

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {

   

        switch pickerView.tag {

           

            case 1:

                return list[row]

            case 2:

                return matrixList[row]

            case 3:

                return controlMethodList[row]

            case 4:

                return controlDetailsList[row]

            case 5:

                return matrixList[row]

           

            default:

                return “”

 

            }

       

        }

  func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

 

    

      switch pickerView.tag {

        

        case 1:

            self.dropDown.isHidden = true

            return textBox.text = self.list[row]

        

        case 2:

            self.trafficHazardsPicker.isHidden = true

            return matrixText.text = self.matrixList[row]

        

        case 3:

            self.controlMethodPicker.isHidden = true

            return controlMethodText.text = self.controlMethodList[row]

    

        case 4:

        

            self.controlDetailsPicker.isHidden = true

            controlDetailsText.text = self.controlDetailsList[row]

 

 

      // i need  to add lines for additional text fields her, such as..

// self.controlDetailsPicker.isHidden = true

// DOCTH1.text = self.controlDetailsList[row]

 

        case 5:

            self.matrixAfterPicker.isHidden = true

            return matrixRatingAfterText.text = self.matrixList[row]

   

    

        default:

    

 

        return ()

    

 

        }

    }

    

    func textFieldDidBeginEditing(_ textField: UITextField) {

    

        /

    

        textField.resignFirstResponder()

    

    

        if textField == self.textBox{

        

            self.dropDown.isHidden = false

            textBox.endEditing(true)

        

        }else{

        

            if textField == self.matrixText {

            

                self.trafficHazardsPicker.isHidden = false

                matrixText.endEditing(true)

            

            }else{

            

                if textField == self.controlMethodText {

                

                

                    self.controlMethodPicker.isHidden = false

                    controlMethodText.endEditing(true)

                

                }else{

                

                    if textField == self.controlDetailsText {

                    

                        self.controlDetailsPicker.isHidden = false

                        controlDetailsText.endEditing(true)

                    

                    

                    }else{

                    

                        if textField == self.matrixRatingAfterText {

                        

                            self.matrixAfterPicker.isHidden = false

                            matrixRatingAfterText.endEditing(true)

                        

                    

                        }else{

                        

                            if textField == self.DOCTH1 {

                           

                                self.controlDetailsPicker.isHidden = false

                                DOCTH1.endEditing(true)

                        

                        }else{

                            

                            if textField == self.DOCTH2 {

                                

                                self.controlDetailsPicker.isHidden = false

                                DOCTH2.endEditing(true)

                                

                        }else{

                            

                            if textField == self.DOCTH3 {

                            

                                self.controlDetailsPicker.isHidden = false

                                DOCTH3.endEditing(true)

                                }

                              …….

Powered by WPeMatico

About

You may also like...

Comments are closed.