Its like this.
A presents B. Here, A is parent of B (Here, A.modalViewController will be B and B.parentViewController will be A)
And B presents C. Here, B is parent of C (Here, B.modalViewController will be C and C.parentViewController will be B)
According to apple guidelines, its responsibility of parent controller to dismiss its child controller.
So if you want to dismiss controller C, you call dismissModalViewController at C.parentViewController. As C's parent is B, thus B is dismissing its modal (child) controller that it presented.
But you want to even dismiss B. Its responsibility of B's parent to dismiss B. So you need to say [B.parentViewController dismissModalViewControllerAnimated: YES];
Thus, you need to get B from C as C.parentViewController (Don't forget to typecast here). Then you say that [B.parentViewController dismissModalViewControllerAnimated: YES];