Change UIAlertController message or title during its presentation
this is possible of course, please check the following:
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"
}
}
It is possible to change the title and/or text AND animate the change, thusly:
[UIView transitionWithView: alertController.view
duration: 0.3
options: UIViewAnimationOptionTransitionCrossDissolve
animations: ^(void) {
alertController.message = newMessage;
}
completion: nil];
Or in Swift:
UIView.transition(with: alertController.view,
duration: 0.3,
options: .transitionCrossDissolve,
animations: { alertController.message = newMessage }
)