I want to display an alert screen using UIAlertController
in viewDidAppear()
and wait until the button is pressed (iOS 11).
When displaying UIAlertController
by present, the alert screen is called in viewDidAppear()
, but it is not displayed and the screen can not be tapped.
Alert screen by asynchronous or delayed execution. The alert screen is displayed without any problem.
Is there any good way to get in sync?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
var doneloop = false
let alert = UIAlertController(title:"Title", message: "Message", preferredStyle: UIAlertControllerStyle.alert)
let action1 = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {
(action: UIAlertAction!) in
print("push OK button")
doneloop = true // Runloop flag
})
alert.addAction(action1)
self.present(alert, animated: false, completion: nil)
while !doneloop {
RunLoop.current.run(until: Date(timeIntervalSinceNow: 0.1))
}
alert.dismiss(animated: false, completion: nil)
}