self.dismiss does nothing on 3rd level segue

∥☆過路亽.° 提交于 2019-12-06 12:13:42
hardik parmar

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)

While in a UINavigationController, You should use the function

_ = navigationController?.popViewController(animated: true)

Or if you want to go back to the very top level view, use:

_ = navigationController?.popToRootViewController(animated: true)

The Apple Documentation for this function explains:

This method removes the top view controller from the stack and makes the new top of the stack the active view controller. If the view controller at the top of the stack is the root view controller, this method does nothing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!