pmusolino / PMAlertController

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

Not presenting nested Alerts #75

Closed joelcorporan closed 5 years ago

joelcorporan commented 5 years ago

When presenting the alert view controller, if it is dismissed, and showed again it does not work. Below an example of the code.

let alertController = PMAlertController(title: "Register Sensor", description: String(format: "Please enter the activation code and owner's email of the %@ sensor", arguments: [serialNumber]), image: nil, style: .alert)

        alertController.addTextField({ (textField) -> Void in
            textField?.placeholder = "Activation Code"
            textField?.textAlignment = .center

        })

        alertController.addTextField({ (textField) -> Void in
            textField?.placeholder = "Owner's Email"
            textField?.keyboardType = .emailAddress
            textField?.textAlignment = .center
        })

        alertController.addAction(PMAlertAction(title: "Save", style: .default, action: {
            () -> Void in
            let activationCode = alertController.textFields[0] as UITextField
            let ownerEmail = alertController.textFields[1] as UITextField

            if let code = activationCode.text, let email = ownerEmail.text, code != "", email != "" {
                self.activateSensor(serialNumber: serialNumber, code: code, owner: email, returnCompletion: {
                    (success, object) -> Void in
                    if success {
                        self.getSensors(true)
                    } else {
                        let error = object as? String
                        AlertView.alert(view: self, "Error", message: error ?? "", completion: {
                            (alert) -> Void in
                            self.present(alertController, animated: true, completion: nil)
                        })
                    }
                });
            } else {
                AlertView.alert(view: self, "Error", message: "Please input both activation code and owner's email", completion: {
                    (alert) -> Void in
                    self.present(alertController, animated: true, completion: nil)
                })
            }
        }))

        alertController.addAction(PMAlertAction(title: "Cancel", style: .cancel, action: nil))

        self.present(alertController, animated: true, completion: nil)
joelcorporan commented 5 years ago

I was able to resolve the problem by adding alertView.gravityDismissAnimation = false