How to Dismiss a Modal Segue Then Perform Push Segue to New View Controller

How can I dismiss a modal segue then perform push segue to new view controller

Update your code as,

func textFieldShouldReturn(textField: UITextField) -> Bool {
var searchNav = SearchNavigationController()
self.dismissViewControllerAnimated(true, completion: {self.presentingViewController.goToNextView()})
return true
}

Performing segue after sender view controller is dismissed

Based on a modification to this answer, the following should work:

In your storyboard, remove the segue that is triggered by tapping your menu button and goes to Destination.

Create a new segue that goes from the Origin view controller to Destination view controller. This segue is going to be manually performed.

When your Destination option is selected in Menu, have Menu dismiss itself and then perform the Destination segue on Origin, like this:

    // This code goes in Menu, and you should call it when
// the menu button is tapped.
//
// presentingViewController is Origin
weak var pvc = self.presentingViewController

self.dismiss(animated: true) {

// Menu has been dismissed, but before it is destroyed
// it calls performSegue on Origin
pvc?.performSegue(withIdentifier: "openDestination", sender: nil)
}

When Destination is dismissed, you should see Origin, without seeing Menu at all.

I tested this in a sample app where "Menu" was not a slide out, but a full modal view controller, and it worked for me.

EDIT: While troubleshooting with @KingTim, he found that we needed to wire the segue from the UINavigationController, not Origin, to the Destination. This is because Origin is inside a navigation controller. After that discovery, it worked.

Dismiss modal, then immediately push view controller

You can't push a view controller into a view dismissed, if it's dismissed it disappears so it's not logical to push another view, cause the parent view controller is deleted. Probably you have this:
- ViewController 1 --> Modal ViewController 2 -->Wanted to dismiss VC2 and push VC3

What you have to do is
- ViewController 1 --> Modal ViewController 2 --> Dismiss VC2 --> Push VC3 on VC1

You can do it with notifications. The most efficient way is to use delegates, create a delegate on VC2 that notifies V1 when it dismisses and then just push VC3.

How to dismiss a modal that was presented in a UIStoryboard with a modal segue?

There isn't any storyboard magic for dismissing a modal view controller without writing at least a little bit of code.

But while you do have to implement some code of your own, you don't necessarily have to go to that much trouble. You can just have a button in view controller B that calls [self dismissViewControllerAnimated:YES completion:nil]. (The docs say the presenting view controller should be the one to dismiss, but they also say that the message will be forwarded to the presenting view controller if called on the presentee. If you want to be more explicit about it -- and you'll need to be in some cases, like when one modal view controller is presented from another -- you can explicitly reference the presenter with self.presentingViewController and call dismiss... from there.)

You see the delegate business in some apps because it's one way of notifying view controller A about whatever the user did while in view controller B... but it's not the only way. There's KVO, notifications, or just plain calling A's methods after referencing it with self.presentingViewController (assuming B knows it's always getting presented by A). And if A doesn't need to know about what happened in B (say, because the user hit a Cancel button), there's no need to do any of that -- you can just dismiss the modal and be done with it.


In iOS 6 and later, unwind segues add another option, providing a little bit of "storyboard magic" for dismissing modal view controllers (or otherwise "backing out" of a sequence of segues). But this approach still requires some code -- you can't set it up entirely in storyboard. On the plus side, though, that code provides a path for getting info from the view controller being dismissed (B) to the one that presented it (A).

Apple has a tech note about unwind segues that covers them in detail, but here's the short version:

  1. Define an IBAction method on the view controller class you want to unwind to -- the one that presents a modal view controller, not the modal view controller itself (view controller A in your question). Unlike normal IBAction methods, these should take a parameter of type UIStoryboardSegue *; e.g.

    - (IBAction)unwindToMainMenu:(UIStoryboardSegue*)sender
  2. In the presented view controller (B in the question), wire a control to the green Exit icon, and choose the method you defined.

  3. In your unwind method implementation, you can refer to the segue's sourceViewController to retrieve information from the view controller being dismissed. You don't need to call dismissViewControllerAnimated:completion: because the segue handles dismissing the view controller that's going away.

Dismiss modal segue

As per the tutorial link you have given in question.

There is a APPViewController which is root for the UIPageViewController and also in AppDelegate, so on top of that view, require a Skip button which is above all the subViews in AppViewController. So its IBAction event will be in AppViewController only.

Now first change your AppDelegate self.window.rootViewController to LoginViewController.
In LoginViewController viewDidLoad event, presentModal UIPageViewController.

Now in its action event of skip button, you can write like this:

[self dismissViewControllerAnimated:YES completion:nil];

So it will automatically dismiss all your AppChildViewControllers, and will display LoginViewController, which is already behind.

This is just a base logic to achieve your goal, you might require to change code as per your project implementation.

Hope this helps.

Dismissing a modal view controller and THEN performing a segue

There is an option I can suggest. You can instantiate view controller using the approach

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
id controllerToPush = [storyboard instantiateViewControllerWithIdentifier:@"desiredViewController"];

(MainStoryboard_iPhone and desiredViewController are specified in interface builder). Then push this controller. For instance, if you're using Navigation controller pattern:

[self.navigationController setViewControllers:@[controllerToPush] animated:YES];

Xcode - Show segue from modal view controller

For anyone who has this issue in the future, I figured it out:

You need another navigation controller. So I perform a modal segue to a new navigation controller, and set the modal view controller as the root view controller of the navigation controller. I can then perform a show segue from the modal view controller to any other as normal.

:)



Related Topics



Leave a reply



Submit