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 ? } 
3
  • Look here In action you have to create closure:) I hope this help stackoverflow.com/questions/26567413/… Commented Oct 21, 2019 at 23:01
  • what do you mean with closure ? Commented Oct 22, 2019 at 14:47
  • it still doesnt work :/ Commented Oct 22, 2019 at 14:54

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.