Zalak Patel
Zalak Patel

Reputation: 1965

UIAlertView displays alert showing late than when required ios

I am using UIAlertView to display alert and it is working for first time that when i click alert appears but when second time i do it then on clicking twice alert gets displayed instead of 1st click.

During secong time "visited full" gets printed on 1st click but alert appears on 2click, Why does this appear?Please help me to resolve.Thanks in advance

println("visited full")
var alert:UIAlertView = UIAlertView(title: "Video", message: "You have played all videos", delegate: self, cancelButtonTitle: "OK")
  alert!.show()

Upvotes: 5

Views: 4449

Answers (1)

Dharmesh Kheni
Dharmesh Kheni

Reputation: 71854

IF it doesn't work then try this may be this will work.

let alert = UIAlertController(title: "Video", message: "You have played all videos", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)

EDIT: I think you can use it like this way too:

dispatch_async(dispatch_get_main_queue(), {
    var alert:UIAlertView = UIAlertView(title: "Video", message: "You have played all videos", delegate: self, cancelButtonTitle: "OK")
    alert.show()
})

and for UIAlertController

dispatch_async(dispatch_get_main_queue(), {
    let alert = UIAlertController(title: "Video", message: "You have played all videos", preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
    self.presentViewController(alert, animated: true, completion: nil)
})

Upvotes: 12

Related Questions