在UIAlertController
呈现ViewController
时,是否可以更改@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
}
}
}
的标题或消息文本。
例如,当用户按下带有此消息的按钮时,我会发出警告:
“等待兑换代码”
然后我使用 Alamofire 发出请求并获取代码,在我拥有它之后,我想要从警报中更改消息而不会再次出现并再次呈现,例如新的消息文本是它:
“您的兑换代码为:########”
更新
这是我的代码:
import java.util.Scanner;
public class AverageMaxMin {
public static void main(String[] args) {
System.out.println("Enter 4 numbers:");
Scanner input=new Scanner(System.in);
double a,b,c,d;
double avg;
a=input.nextDouble();
b=input.nextDouble();
c=input.nextDouble();
d=input.nextDouble();
avg=(double)(a+b+c+d)/4.0;
System.out.println("The Average is: " + avg);
}
}
答案 0 :(得分:5)
这当然是可能的,请检查以下内容:
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"
}
}
答案 1 :(得分:0)
只需将alertcontroller定义为:
var controller:UIAlertController?
然后像这样初始化你的警报控制器:
controller = UIAlertController(title: "Title", message: "Yo", preferredStyle: .alert)
self.present(controller!, animated: true, completion: nil)
现在,当您从服务器获取数据时,请调用:
self.controller?.title = "New Title"
答案 2 :(得分:0)
displayMyAlertMessage(userMessage:“Keshav Gera”);
func displayMyAlertMessage(userMessage: String)
{
let alert = UIAlertController(title: "Success", message: userMessage, preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default, handler: nil)
let imgTitle = UIImage(named:"imgTitle.png")
let imgViewTitle = UIImageView(frame: CGRect(x: 10, y: 10, width: 30, height: 30))
imgViewTitle.image = imgTitle
alert.view.addSubview(imgViewTitle)
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
}
答案 3 :(得分:0)
可以更改标题和/或文本,并对更改进行动画处理,从而:
[UIView transitionWithView: alertController.view
duration: 0.3
options: UIViewAnimationOptionTransitionCrossDissolve
animations: ^(void) {
alertController.message = newMessage;
}
completion: nil];