问题描述
我将从另一个modalviewcontroller呈现一个modalviewcontroller。当我解雇第二个modalviewcontroller时,第一个和第二个modalviewcontroller都应该被解雇。我试图访问第一个模态视图,如
I am presenting a modalviewcontroller from another modalviewcontroller. When I dismiss the second modalviewcontroller both the first and second modalviewcontroller should get dismissed. I tried to access the first modalview like
[self.view.superview dismissmodalviewcontroller];
但显示错误。从第二个获取第一个modalViewController并从中调用dismiss方法的正确方法是什么?
but it is showing error. What is the right way to get a ref to the first modalViewController from the second one and invoke the dismiss method from it?
推荐答案
就像这样。
一个礼物B.这里,A是B的父亲(这里,A.modalViewController将是B,而B.parentViewController将是A)
A presents B. Here, A is parent of B (Here, A.modalViewController will be B and B.parentViewController will be A)
B表示C.这里,B是C的父(这里,B.modalViewController将是C,而C.parentViewController将是B)
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.
因此,如果你想解雇控制器C,你可以调用dismissModalViewController C.parentViewController。由于C的父母是B,因此B正在解雇它所呈现的模态(子)控制器。
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.
但是你想要解雇B.它的B的父母有责任解雇B.所以你需要说[B.parentViewController dismissModalViewControllerAnimated:YES];
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];
因此,你需要从C中获取B作为C.parentViewController(别忘了这里的类型。然后你说[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];
这篇关于从另一个modalviewcontroller中解除modalviewcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!