If I call (In an UIViewController
)
alert.dismiss(animated: false, completion: nil)
print("executed after dismiss?")
Given that alert is a previously presented UIAlertController
, does the dismiss method execute synchronously?
Could I do:
alert.dismiss(animated: false, completion: nil)
let newAlert = UIAlertController(...)
present(newAlert, animated: true, completion: nil)
Without having to worry about a problem while presenting newAlert
?
Like most animation methods when you dismiss the UIAlertController
you are just getting the ball rolling. The view controller is dismissed and removed asynchronously. To test this we can use some code like this:
let alert = UIAlertController(title: "Oh No!", message: ":(", preferredStyle: UIAlertControllerStyle.alert)
self.present(alert, animated: true, completion: nil)
print(presentedViewController) // Optional(<UIAlertController: 0x7fefe901e670>)
alert.dismiss(animated: true, completion: nil)
print(presentedViewController) // Optional(<UIAlertController: 0x7fefe901e670>)
As demonstrated above the alert view controller is not removed as the presented view controller right away. You can still present the new alert right after dismissing the old alert. However best practice would be to place your code for the second alert in the completion handler of the first. This completion handler is called after viewDidDisappear
is called on the presented view controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With