So when the function dissmissAlert has completed (the first alertDialog disappears). I want the following alertDialog to show directly afterwards, which is created in the func saveLogin.
typealias FinishedAlert = () -> Bool
var firstPasswordSaveAlert: UIAlertController!
@IBAction func saveLogin(_ sender: Any) {
if loginPasswordTf.text != "" {
showAlert()
}
if FinishedAlert == true {
UserDefaults.standard.set(loginPasswordTf.text, forKey: "loginpassword")
let alert = UIAlertController(title: "You need it to access this app", message: "Here it is: " + String(describing: UserDefaults.standard.object(forKey: "loginpassword")!), preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Got it!", style: UIAlertActionStyle.destructive, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
func showAlert() {
if loginPasswordTf.text != "" {
self.firstPasswordSaveAlert = UIAlertController(title: "IMPORTANT", message: "It's very important that you remember your password", preferredStyle: UIAlertControllerStyle.alert)
self.present(self.firstPasswordSaveAlert, animated: true, completion: nil)
Timer.scheduledTimer(timeInterval: 5.0, target: self, selector: #selector(ViewController.dismissAlert), userInfo: nil, repeats: false)
}
}
func dismissAlert(completed: FinishedAlert) {
// Dismiss the alert from here
self.firstPasswordSaveAlert.dismiss(animated: true, completion: nil)
completed()
}
How do I check if dismissAlert() completed it's tasks?
Thanks!
Aucun commentaire:
Enregistrer un commentaire