Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How dismiss a viewController with storyboard from a push segue?

I don't know why dismissViewControllerAnimated:completion:. I just want to do it.

I start with a

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

But is I call the dismiss than nothing happens. I can create another segue, but it create a new view controller.

My question is: How dismiss the performSegueWithIdentifier:sender:?

like image 708
Rodrigo Avatar asked Apr 23 '12 04:04

Rodrigo


People also ask

How do I dismiss a presented ViewController?

When it comes time to dismiss a presented view controller, the preferred approach is to let the presenting view controller dismiss it. In other words, whenever possible, the same view controller that presented the view controller should also take responsibility for dismissing it.

How do you unwind a segue?

In storyboard, go to the view that you want to unwind from and simply drag a segue from your button or whatever up to the little orange "EXIT" icon at the top right of your source view. That's it, your segue will unwind when your button is tapped.

How do you dismiss a view?

The first option is to tell the view to dismiss itself using its presentation mode environment key. Any view can read its presentation mode using @Environment(\. presentationMode) , and calling wrappedValue. dismiss() on that will cause the view to be dismissed.

How do you dismiss the current view controller and go to another view in Swift?

This second controller has a dismiss option that just comes back to the root view controller and a button that when the user touches it dismisses the current view controller so it goes back to the root view controller for a second and presents another one.


2 Answers

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

like image 100
RayInNoIL Avatar answered Oct 31 '22 11:10

RayInNoIL


You could just call

[self dismissViewControllerAnimated:YES completion:nil];

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

like image 43
carrotzoe Avatar answered Oct 31 '22 09:10

carrotzoe