Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
like image 327
Zalak Patel Avatar asked Nov 12 '14 09:11

Zalak Patel


Video Answer


1 Answers

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)
})
like image 164
Dharmesh Kheni Avatar answered Oct 21 '22 02:10

Dharmesh Kheni