Present a view controller, dismiss it and present a different one in Swift

The error occurs because you are trying to present SecondController from FirstController after you have dismissed FirstController. This doesn’t work:

self.dismiss(animated: true, completion: {
    let vc = SecondController()

    // 'self' refers to FirstController, but you have just dismissed
    //  FirstController! It's no longer in the view hierarchy!
    self.present(vc, animated: true, completion: nil)
})

This problem is very similar to a question I answered yesterday.

Modified for your scenario, I would suggest this:

weak var pvc = self.presentingViewController

self.dismiss(animated: true, completion: {
    let vc = SecondController()
    pvc?.present(vc, animated: true, completion: nil)
})

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)