pmusolino / PMAlertController

PMAlertController is a great and customizable alert that can substitute UIAlertController
MIT License
2.53k stars 186 forks source link

Completion on dismiss did not called #65

Closed hendyevan closed 6 years ago

hendyevan commented 6 years ago

Hi this is an awesome library. Im using it since swift 3 for almost my whole project. Now im using swift 4 version and run into some trouble. alertVC.dismiss(animated: false, completion: { () in self.dismiss(animated: true, completion: nil) }) In swift 3 version, the completion block run well. However, after upgrade to swift 4, the completion block did not called. Please help me :D

pmusolino commented 6 years ago

Hi @hendyevan can you post all the code that you use when you show the alert?

Thanks -Paolo

hendyevan commented 6 years ago

Hi @pmusolino , I create custom function : func showAlertOneButton(title: String, description: String, style: PMAlertControllerStyle, okAction: PMAlertAction) -> PMAlertController { let alertVC = PMAlertController(title: title, description: description, image: nil, style: style) alertVC.addAction(okAction) self.present(alertVC, animated: true, completion: nil) return alertVC }

and then im using it like : var alertVC = PMAlertController() let okAction = PMAlertAction(title: "OK", style: .default, action: { () -> Void in alertVC.dismiss(animated: true, completion: { () in self.dismiss(animated: true, completion: nil) }) }) alertVC = self.showAlertOneButton(title: "Title", description: "\(error.localizedDescription)", style: .alert, okAction: okAction)

func self.dismiss inside completion block did not called.

pmusolino commented 6 years ago

You don't need to call alertVC.dismiss, because the alert is automatically dismissed when the user taps inside the button.

hendyevan commented 6 years ago

Great, it's work. Thank you very much @pmusolino :D