In order to display alerts, I made a simple class:
Now I make a class to this class, from another class, like this:
Everyting is OK, but when I tap the OK button, the handler is never called
Code Block public protocol AlertDisplayer { func displayAlert(with title: String, message: String, actions: [UIAlertAction]?, completion: (() -> Void)?) } extension AlertDisplayer where Self: UIViewController { public func displayAlert(with title: String, message: String, actions: [UIAlertAction]? = nil, completion: (() -> Void)? = nil ) { guard presentedViewController == nil else { return } let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) actions?.forEach { action in alertController.addAction(action) } present(alertController, animated: true, completion: nil) //{ } }
Now I make a class to this class, from another class, like this:
Code Block func passwordForgot(navigation: UINavigationController, email: String?) { let model = loginModel() model.rappelpwd(controller: navigation.topViewController as! AlertDisplayer, email: email!) { result in if result.result! { let defaultAction = UIAlertAction(title: "OK", style: .default, handler: { action in Swift.print("ok tapped") //presentControllerLogin() }) let title = "Attention" let aController = navigation.topViewController as? AlertDisplayer if aController != nil { aController!.displayAlert(with: title , message: result.msg!, actions: [defaultAction], completion: nil) } } } }
Everyting is OK, but when I tap the OK button, the handler is never called