【发布时间】:2019-02-06 09:18:30
【问题描述】:
我正在使用以下代码将 textField 添加到 UIAlertController:
let anAlertController = UIAlertController(title:title, message:message, preferredStyle: .alert)
weak var weakSelf = self
let aDefaultAction = UIAlertAction(title:defaultTitle, style: UIAlertAction.Style.default) {
UIAlertAction in
anAlertController.addAction(aDefaultAction)
}
let aCancelAction = UIAlertAction(title:canceltTitle, style: UIAlertAction.Style.cancel) {
UIAlertAction in
}
anAlertController.addAction(aCancelAction)
anAlertController.addTextField { (textField) in
textField.textAlignment = NSTextAlignment.center
textField.text = "textFieldText"
textField.delegate = self
textField.resignFirstResponder()
}
self.present(anAlertController, animated: true, completion: nil)
当我尝试呈现 UIAlertController 时,文本字段会自动成为第一响应者。我不希望 textfield 在呈现警报时成为第一响应者。我用谷歌搜索并尝试了几种方法来避免这种情况,但没有运气。谁能告诉我如何做到这一点?
【问题讨论】:
-
显示一些与此相关的附加代码
-
@Anbu.Karthik 更新了代码。请检查
-
你检查我的答案吗? stackoverflow.com/a/54550421/820795
-
@Gralex。仍然弹出键盘
-
你确定你没有遗漏什么吗?检查模拟器和设备(iOS 12),一切正常。
标签: ios swift uialertcontroller first-responder