gpt4 book ai didi

iOS:UIAlertController 上的 textField 成为出现警报时的第一响应者

转载 作者:行者123 更新时间:2023-11-28 13:51:27 25 4
gpt4 key购买 nike

我正在使用以下代码将 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 时,文本字段自动成为第一响应者。我不希望文本字段在显示警报时成为第一响应者。我用谷歌搜索并尝试了几种方法来避免这种情况但没有运气。谁能告诉我如何实现这一目标?

最佳答案

试试这个

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
}

})

关于iOS:UIAlertController 上的 textField 成为出现警报时的第一响应者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54550116/

25 4 0
文章推荐: css - 文本
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com