【发布时间】:2016-10-28 21:06:16
【问题描述】:
当UIAlertController 出现时,是否可以更改UIAlertController 的标题或消息文本。
例如,当用户按下带有此消息的按钮时,我会发出警报:
“等待兑换码”
然后我使用 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
}
}
}
【问题讨论】:
-
是的,只需更新
title或message属性。 -
@Paulw11 我在 Alamofire 请求的 callback 中尝试过,但没有任何反应...
-
我可以获取 MainQueue 并更新此属性吗?
-
@Santiagocarmonagonzalez 你确定到达那行代码吗?
-
@alexburtnik 我完全确定,因为我使用断点还在控制台中打印我从请求中得到的代码
标签: ios swift uialertcontroller