0

i have created a alert with two textfields and the inputView of the second texfield is a pickerview. I can access the text of the first textfield by alert.textfields?.first?.text. I want to display the picker view items in the second textfield, but i dont know how to access the secondTextfield.text in the picker view function didSelectRow. how can i fix it ?

 buttonAnimation(button: addButton)
     passwordStringArray.insert("\(passwordLabel.text ?? "")", at: 0)

        let alert = UIAlertController(title: "\(passwordLabel.text ?? "")", message: "customize your password", preferredStyle: .alert)

        alert.addTextField { (notesTextfield) in
            notesTextfield.placeholder = "type in some notes"
            notesTextfield.textAlignment = .center
        }
        alert.addTextField { (categoryTextfield) in
            categoryTextfield.placeholder = "choose your password category"
            categoryTextfield.textAlignment = .center
            categoryTextfield.inputView = self.picker

        }

        let actionSave = UIAlertAction(title: "save", style: .default) { (cancelButton) in
            self.dismiss(animated: true, completion: nil)
            self.passwordNotesArray.insert("\(alert.textFields?.first?.text ?? "")", at: 0)
//            self.passwordCategory.insert(categorytextfield.text)

            self.performSegue(withIdentifier: "segue", sender: self)
        }

        let actionCancel = UIAlertAction(title: "cancel", style: .default) { (saveButton) in
            self.dismiss(animated: true, completion: nil)

        }

        alert.addAction(actionCancel)
        alert.addAction(actionSave)

        self.present(alert, animated: true)
    }





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

        // how can i access alert.textfield.categorytectfield.text here ?
    }
flolopi
  • 43
  • 6

1 Answers1

0

You can do it only as a placeholder if you want. If you want to do that you have to create an alert function which get one argument like from picker function. You want it as a placeholder or not? WIth placeholder it is quite simple. If you want to put there data I think this is impossible because, alert should get data, not to have inside.

To put data to alert your alert function need to take one String argument from pickerView. Alert has to be called inside of pickerview didselect function.

motivated
  • 53
  • 8