Dismiss UIAlertView after 5 Seconds Swift

后端 未结 10 1757
悲哀的现实
悲哀的现实 2020-12-22 20:31

I\'ve created a UIAlertView that contains a UIActivityIndicator. Everything works great, but I\'d also like the UIAlertView to disappear after 5 seconds.

Ho

10条回答
  •  我在风中等你
    2020-12-22 20:48

    in swift 2 you can do this. Credit to @Lyndsey Scott

     let alertController = UIAlertController(title: "youTitle", message: "YourMessage", preferredStyle: .Alert)
                    self.presentViewController(alertController, animated: true, completion: nil)
                    let delay = 5.0 * Double(NSEC_PER_SEC)
                    let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
                    dispatch_after(time, dispatch_get_main_queue(), {
                        alertController.dismissViewControllerAnimated(true, completion: nil)
                    })
    

提交回复
热议问题