Log*_*ger 1 first-responder ios swift uialertcontroller
我使用以下代码将 textField 添加到 UIAlertController 中:
\n\nlet anAlertController = UIAlertController(title:title, message:message, preferredStyle: .alert)\n weak var weakSelf = self\n\n let aDefaultAction = UIAlertAction(title:defaultTitle, style: UIAlertAction.Style.default) {\n UIAlertAction in\n\n anAlertController.addAction(aDefaultAction)\n }\n\n let aCancelAction = UIAlertAction(title:canceltTitle, style: UIAlertAction.Style.cancel) {\n UIAlertAction in\n }\n anAlertController.addAction(aCancelAction)\n\n anAlertController.addTextField { (textField) in\n textField.textAlignment = NSTextAlignment.center\n textField.text = "textFieldText"\n textField.delegate = self\n textField.resignFirstResponder()\n }\n self.present(anAlertController, animated: true, completion: nil)\nRun Code Online (Sandbox Code Playgroud)\n\n当我尝试呈现 UIAlertController 时,文本字段自动成为第一响应者。我不\xe2\x80\x99 不希望文本字段在呈现警报时成为第一响应者。我用谷歌搜索并尝试了几种方法来避免这种情况,但没有运气。有人能告诉如何实现这一目标吗?
\n尝试这个
anAlertController.addTextField { (textField) in
textField.textAlignment = .center
textField.text = "textFieldText"
textField.delegate = self as? UITextFieldDelegate
textField.isEnabled = false
}
self.present(anAlertController, animated: false, completion: {
if let getTextfield = anAlertController.textFields?.first{
getTextfield.resignFirstResponder()
getTextfield.isEnabled = true
}
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
615 次 |
| 最近记录: |