0

I am trying to dimiss a VC and then show a popup with an error

I first tried:

            case .failure(let error):
            self.dismiss(animated: true, completion: nil)
            self.presentMRAlertOnMainThread(title: "Something went wrong", message: error.rawValue, buttonTitle: "Ok")

Then I tried:

            case .failure(let error):
            self.dismiss(animated: true, completion: {
                self.presentMRAlertOnMainThread(title: "Something went wrong", message: error.rawValue, buttonTitle: "Ok")

            })

Then I thought it might be an issue with the threads so I tried:

            case .failure(let error):
            self.dismiss(animated: true, completion: {
               DispatchQueue.main.async {
                self.presentMRAlertOnMainThread(title: "Something went wrong", message: error.rawValue, buttonTitle: "Ok")
                }

            })
Peter
  • 68
  • 9
  • Your second code looks good as it stands, so what is the issue? What does or doesn't happen? Remember, we don't know what `self.presentMRAlert` is or does or where it lives, so please be informative. Your goal is to make _us_ able to _reproduce_ the issue. – matt Mar 14 '20 at 17:02
  • Are you trying to present the alert on the dismissed VC? If so, that won't work. See my answer here: https://stackoverflow.com/questions/43566414/present-a-view-controller-dismiss-it-and-present-a-different-one-in-swift/43566536#43566536 – Mike Taverne Mar 14 '20 at 18:25
  • Hi matt, the present alert is just a popup alert. The issue is I am trying to present the alert on the dismissed vc. It gives error saying: Attempt to present alter for whose view is not in the window hierarchy! – Peter Mar 15 '20 at 05:11

0 Answers0