San*_*lez 6 ios swift uialertcontroller
是否可以更改UIAlertController其ViewController呈现时的标题或消息文本.
例如,当用户按下带有此消息的按钮时,我会发出警报:
"等待兑换代码"
然后我使用Alamofire发出请求并获取代码,在我拥有它之后,我想从警报中更改消息而不会有任何不知情并再次呈现它,例如新的消息文本是:
"您的兑换码是:########"
更新
这是我的代码:
@IBAction func offerAction(_ sender: UIButton) {
var code: String = "Generating códe"
let message: String = "El código para redimir esta oferta es: \(code)"
let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert)
let okAction = UIAlertAction(title: "Accept", style: .default, handler: nil)
let redirect = UIAlertAction(title: "Website", style: .default) { (_) in
// TODO open url web
}
if offer.redeemOfferOnline == .yes {
alert.addAction(redirect)
}
alert.addAction(okAction)
present(alert, animated: true, completion: nil)
offer.code.getRedeemCode(id: offer.id) { (success, data) in
if success {
code = data
alert.message = message
// TODO end the code of changing the message of alert
}
}
}
Run Code Online (Sandbox Code Playgroud)
这当然是可能的,请检查以下内容:
class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let alertController = UIAlertController(title: "My Title", message: "My Message", preferredStyle: .alert)
present(alertController, animated: true, completion: nil)
// Do your queries and get your new title and then set the new title
alertController.title = "Your new title"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5763 次 |
| 最近记录: |