views:

46

answers:

2

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?

A: 

Try using the next code in B (right after dismissing C, as you already do):

[self.parentViewController dismissModalViewControllerAnimated:YES];

IMPORTANT:
Don't do anything in the method after this line.
This view controller (B) probably will be released and deallocated...

Michael Kessler
I tried this but it just simply dismisses C. B is still visible.
Sheehan Alam
Try dismissing C without animation and then dismiss B with animation... BTW, where is this dismissing code located (which class and how is this method called)?
Michael Kessler
Dismissing code is located in C in a method called dismissAll. It is triggered by pressing a UIBarButtonItem.
Sheehan Alam
I was sure that it is located in B when I wrote my answer... The common solution for dismissing modal view controllers is to call a method in delegate (view controller that opened the modal one) and in that method the modal view controller should be dismissed. In your case A should be a delegate of B and B should be a delegate of C; in C you should call a delegate method in B that should dismiss C and call a delegate method in A, that should dismiss B... I hope it is clear enough now.
Michael Kessler
A: 

The navigation controller has a "viewControllers" property that is an array - you can set that to a new array minus the two view controllers you want to remove.

Kendall Helmstetter Gelner
im not sure if i understand you. can you update w/ code?
Sheehan Alam