0

I created a custom alert in a viewcontroller, following the guidelines of the most voted answer of that question: https://stackoverflow.com/a/37275840/6196609

I use this to display the alert, it is used as a "loading".

let pending = UIAlertController()

override func viewDidLoad() {
    super.viewDidLoad()

    […]

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let pending = storyboard.instantiateViewControllerWithIdentifier("alertaLoad")
    pending.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
    pending.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve

    […]

}

to show:

self.presentViewController(self.pending, animated: true, completion: nil)

I succeeded in showing it, but I need to terminate it by the viewcontroller that invoked it after the end of my process, not by itself as was done in the example I quoted. I've tried this but nothing happens.

self.pending.dismissViewControllerAnimated(false, completion: { (vetor) -> Void in
                    […]
                })

How could I do this correctly?

Community
  • 1
  • 1
Athila Zuma
  • 391
  • 1
  • 4
  • 17

1 Answers1

2

Call dismisson the presenting UIViewController, not on the presented one:

self.dismiss(animated: true) {
    // go on
}
shallowThought
  • 19,212
  • 9
  • 65
  • 112