【发布时间】:2018-12-17 14:47:55
【问题描述】:
每当用户从 AlertController 向我的文本字段输入文本并点击 ENTER 按钮时,我都想更改我的标签“teamNameLabel”。
我真的很接近。我只需要输入的文本在点击 ENTER 按钮时显示为我的标签。
另外:有没有办法让输入到我的文本字段中的文本仅大写? (例如,用户必须输入“团队名称”而不是“团队名称”)
查看下面的代码和图片:
@IBAction func editTeamNameButton() {
let message = "Please Enter Below"
let alert = UIAlertController(title: "ENTER TEAM NAME", message: message, preferredStyle: .alert)
let action = UIAlertAction(title: "ENTER", style: .default, handler: nil)
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alert.addAction(action)
alert.addAction(cancelAction)
alert.preferredAction = action
alert.addTextField(configurationHandler: { (textField) in
textField.placeholder = "Eg. TEAM NAME"
})
present(alert, animated: true, completion: nil)
}
【问题讨论】:
-
stackoverflow.com/questions/34504317/…
let textField = alertController.textFields?.first部分允许检索文本字段的内容。
标签: ios swift uialertcontroller