如何解雇所有模态视图?

时间:2012-10-11 22:38:28

标签: iphone objective-c ios

假设我基于A呈现模态视图B,然后基于B呈现模态视图C.

有没有办法解雇B和C并直接回到A?

4 个答案:

答案 0 :(得分:5)

假设您在XCode4.5中使用故事板,则可以使用新的展开segue。实施

 -(IBAction)back:(UIStoryboardSegue*)segue

在A中。(您可以将函数定义留空。)然后在C的控制器中右键单击新的退出图标并将新条目连接到将启动展开的控件。

答案 1 :(得分:5)

是的,我有一些解决方案, 可能它有点脏 但你可以解决

UIViewController* vc = self;

while (vc) {
    UIViewController* temp = vc.presentingViewController;
    if (!temp.presentedViewController) {
        [vc dismissViewControllerAnimated:YES completion:^{}];
        break;
    }
    vc =  temp;
}

你可以从堆栈中的任何模型控制器调用它,所有这些都将被解雇。我们只是在寻找第二个然后解雇它。

答案 2 :(得分:2)

是的,你可以调用[B dismissModalViewControllerAnimated:YES];

这将解雇B.当然,如果C从B出现,它也将被解雇。

而且,这是相对问题,它包含完整的答案。 iPhone - dismiss multiple ViewControllers

答案 3 :(得分:0)

如果 2 ViewContronllers,那么:

[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];

如果有 3 ViewControllers,则:

self.presentingViewController.presentingViewController.presentViewController

相关问题