pmusolino / PMAlertController

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

performSegue as Action and autodismissing [SOLVED] #39

Closed mikall closed 7 years ago

mikall commented 7 years ago

Hi, thanks for this nice controller!

If I use lines of code like this:

alertVC.addAction(PMAlertAction(title: "Only selected supporters.", style: .cancel, action: { () in
            self.performSegue(withIdentifier: "pickA", sender: self)
        }))

The controller pops up and in less then 1 second is dismissing. Is there a way to avoid this behavior? Thank you

Michele

pmusolino commented 7 years ago

What controller pops up and is dismissed, the destination view controller or PMAlertController?

mikall commented 7 years ago

The destination one. if I put a segue inside an action the new viewController is terminated in near real time and the focus comes back to the PMAlertController.

pmusolino commented 7 years ago

I think that problem is this: when you tap a button on PMAlertController the alert is not already dismissed. If how present your VC is the same that present PMAlertController, the main VC can't present another view controller. I suggest you to present the view controller when PMAlertController is totally dismissed. You can check if the problem is this, inserting a timer in the action closure.

Let me know. -Paolo

mikall commented 7 years ago

Following your suggestions I was able to find this solution:

alertVCaudience.addAction(PMAlertAction(title: "Only selected supporters.", style: .cancel, action: { () in alertVCaudience.dismiss(animated: false, completion: { () in self.performSegue(withIdentifier: "pickPublicSegue", sender: self) }) }))

thank you Paolo /Michele