Home How to synchronize the UIAlert in viewDidAppear ()
Reply: 0

How to synchronize the UIAlert in viewDidAppear ()

user1582 Published in April 26, 2018, 1:45 pm

This question is an exact duplicate of:

  • UIAlertController visible only when viewDidAppear has finished its call 2 answers

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) {

    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


    self.present(alert, animated: false, completion: nil)

    while !doneloop {
       RunLoop.current.run(until: Date(timeIntervalSinceNow: 0.1))

    alert.dismiss(animated: false, completion: nil)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.430955 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO