Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Dismiss 2 Modal View Controllers in Succession?

I have 2 view controllers presented modally.

A presents B which presents C. 

When I dismiss C I would like to dismiss B as well. But I am not sure how to do this:

Dismiss C:

[self dismissModalViewControllerAnimated:YES] //[delegate dismissB] //this doesn't work either when i create a delegate pattern 

Now I am left with B. How can I dismiss B from C?

like image 388
Sheehan Alam Avatar asked Jul 11 '10 19:07

Sheehan Alam


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.


1 Answers

Just found out you need to use presentingViewController in iOS 5.

[self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES]; 

A -> B -> C

Running the above code in modal C will take you back to A

like image 146
Andy Davies Avatar answered Oct 14 '22 02:10

Andy Davies