In my quick application, I have a one-button UIViewController.
This button calls up a function that calls up a popup that disappears after 3 seconds. In addition, after this time, he displays a message on the console. The code for this function is as follows:
func showAlertMsg(title: String, message: String){ let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert) self.presentViewController(alertController, animated: true, completion: nil) let delay = 3.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) print("popup disappeared") }) }
This works great, but I would like to make some improvements. I wanted to add a button there that immediately cancels this popup and then does not display a message in the console. Is there a way to display such a popup for the user? In addition, is there a way to show the counter with the number of remaining seconds in this pop-up message that shows how much time is left until the pop-up window disappears?
source share