ios:如何关闭模态视图控制器,然后弹出一个推入的视图控制器 [英] ios: how to dismiss a modal view controller and then pop a pushed view controller
问题描述
我有一个视图控制器B,它由根视图控制器A推送到导航堆栈上,并且如果其模型处于特定状态,则该视图控制器B需要显示替代视图,因此它会模态呈现另一个视图控制器C.当我关闭视图控制器CI时,如果导航控制器B也位于导航堆栈中,则它也要弹出视图控制器B.我希望这样做的方式是只有1个过渡.
I have a view controller B that is pushed onto the navigation stack by root view controller A and this view controller B needs to display an alternative view if its model is in a certain state so it is modally presenting another view controller C. When I dismiss view controller C I would also like to pop view controller B if that is also on the nav stack. I would like to do it in such a way that there is only 1 transition.
有什么想法吗?
推荐答案
在您发布的场景中,视图控制器C的呈现视图控制器实际上将是导航控制器,因此您可以要求它弹出B,然后解雇自己.这段代码在视图控制器C中:
In the scenario you posted, the presenting view controller for view controller C will actually be the navigation controller, so you can ask it to pop off B, and then dismiss yourself. This code is in view controller C:
-(IBAction)goBackToA:(id)sender {
[(UINavigationController *)self.presentingViewController popViewControllerAnimated:NO];
[self dismissViewControllerAnimated:YES completion:nil];
}
如果使用情节提要,则可以执行相同的操作,并以轻松的步调直接跳回A.
If you are using a storyboard, you can do this same thing, jumping directly back to A with an unwind segue.
这篇关于ios:如何关闭模态视图控制器,然后弹出一个推入的视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!