[英]how can i access the text of an Uitextfield in an alert?
我創建了一個帶有兩個文本字段的警報,第二個 texfield 的 inputView 是一個pickerview。 我可以通過 alert.textfields?.first?.text 訪問第一個文本字段的文本。 我想在第二個文本字段中顯示選擇器視圖項目,但我不知道如何在選擇器視圖 function 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 ?
}
如果需要,您只能將其用作占位符。 如果你想這樣做,你必須創建一個警報 function,它會從選擇器 function 中獲取一個參數。 你想要它作為占位符嗎? 使用占位符非常簡單。 如果你想把數據放在那里,我認為這是不可能的,因為警報應該獲取數據,而不是里面。
要放置數據以提醒您的警報 function 需要從 pickerView 中獲取一個字符串參數。 必須在 pickerview didselect function 內部調用警報。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.