How to Dismiss 2 Modal View Controllers in Succession?

Viewed 24721

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?

15 Answers

I know this answer may feel redundant, but the statement below should make sense and you get an idea of how this works.

Just dismiss the oldest view controller and all other later view controllers go away with this.

In case of 2 view controllers:

Objective C:

[self.presentingViewController dismissViewControllerAnimated:true completion:nil]

Swift:

presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
Related