Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios: how to dismiss a modal view controller and then pop a pushed view controller

I have a view controller B that is pushed onto the navigation stack by root view controller A and this view controller B needs to display an alternative view if its model is in a certain state so it is modally presenting another view controller C. When I dismiss view controller C I would also like to pop view controller B if that is also on the nav stack. I would like to do it in such a way that there is only 1 transition.

Any ideas?

like image 977
Heisenberg Avatar asked May 01 '13 01:05

Heisenberg


People also ask

How do you dismiss a modal view controller?

According to the View Controller Programming guide for iPhone OS, this is incorrect when it comes to dismissing modal view controllers you should use delegation. So before presenting your modal view make yourself the delegate and then call the delegate from the modal view controller to dismiss.

How do you dismiss a pushed view controller in Swift?

If you are using pushviewcontroller method then to dismiss you have to use popviewcontroller method .

How do I go back to the previous view controller in iOS 4?

Open your storyboard where your different viewController are located. Tap the viewController you would like your navigation controller to start from. On the top of Xcode, tap "Editor" -> Tap embed in.


1 Answers

In the scenario you posted, the presenting view controller for view controller C will actually be the navigation controller, so you can ask it to pop off B, and then dismiss yourself. This code is in view controller C:

-(IBAction)goBackToA:(id)sender {
    [(UINavigationController *)self.presentingViewController  popViewControllerAnimated:NO];
    [self dismissViewControllerAnimated:YES completion:nil];
}

If you are using a storyboard, you can do this same thing, jumping directly back to A with an unwind segue.

like image 164
rdelmar Avatar answered Oct 16 '22 01:10

rdelmar