我创建了一个带有两个文本字段的警报,第二个 texfield 的 inputView 是一个pickerview。我可以通过 alert.textfields?.first?.text 访问第一个文本字段的文本。我想在第二个文本字段中显示选择器视图项,但我不知道如何在选择器视图函数 didSelectRow 中访问 secondTextfield.text。我该如何解决?
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 ?
}