Search code examples
iosswiftseguedismiss

self.dismiss does nothing on 3rd level segue


I have a view controller embedded in a navigation controller. I segue to a view controller via a "show" segue. From there I navigate to a tableviewcontroller via a "show" segue. The navigation bar shows up with the back button but upon didclickrow self.dismiss does nothing. The completion block never executes. I'm baffled. There has to be some rule I don't understand about view controllers.

self.dismiss(animated: true, completion: {
    print( "THIS NEVER EXECUTES AND NOTHING HAPPENS" )
})    

Solution

  • The "show segue" is used to push a view controller. So your code will not work as you are trying to dismiss the view controller that was not presented.

    You should dismiss only when a view controller is presented or you have used a "Present Modally Segue" type.

    You should use popViewController when you have used "Push Segue" type or have pushed a view controller.

    self.navigationController?.popViewController(animated: true)