How dismiss a viewController with storyboard from a push segue?

本小妞迷上赌 提交于 2019-12-03 07:21:16

Do you have a navigationBar in the viewController that's calling:

[self performSegueWithIdentifier:@"my_segue" sender:self];

If so, you'll need to use:

[self.navigationController popViewControllerAnimated:YES];

to pop the view off the stack. There's one segue call, but the framework seems to call:

presentViewController:animated:completion:

or:

pushViewController:animated:

as appropriate.

Ray

You could just call

[self dismissViewControllerAnimated:YES completion:nil];

from the view controller since the view controller was pushed by segue.

[my_segue_view_controller dismissModalViewControllerAnimated: YES] ?

(not sure, but it works in my practice)

performSegueWithIdentifier:sender: itself isn't dismissed, that's just the method that's called to initiate a named segue. What happens in the segue is of more interest.

You're right that you should call dismissViewControllerAnimated:completion:, and it should be called by the presenting view controller, which has previously called the presented view controller using presentViewController:animated:completion:. For more info, see the UIViewcontroller docs.

Use the below code for Swift 4 version

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