I have a situation where I want to present a UIAlertController
in order to wait for an event (asynchronous request for data from third party) to finish before showing my main ViewController
to the user to interact with.
Once the asynchronous code finishes, then I want to dismiss the UIAlertController
. I know that normally UIAlertControllers are setup with a button to dismiss it, which is input from the user. I am wondering if what I want to do (dismiss with an event instead of user input) is possible?
So far, I tried to show the UIAlertController
, and then wait in a while loop checking a boolean for when the event occurs:
var alert = UIAlertController(title: "Please wait", message: "Retrieving data", preferredStyle: UIAlertControllerStyle.Alert)
self.presentViewController(alert, animated: true, completion: nil)
// dataLoadingDone is the boolean to check
while (!dataLoadingDone) {
}
self.dismissViewControllerAnimated(true, completion: nil)
This gives a warning
Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!
and does not dismiss the UIAlertController. I also tried alert.dismissViewControllerAnimated(true, completion: nil)
instead of self.dismissViewControllerAnimated(true, completion: nil)
, but this doesn't get rid of the UIAlertController
either.