如何在singleview应用程序中将thirdviewcontroller弹出到firstviewcontroller

时间:2014-05-13 09:33:13

标签: ios uiviewcontroller

在我的app我有三个uiviewcontroller:firstviewcontroller,secondviewcontroller和thirdviewcontroller。

我使用navigationcontroller从firstviewcontroller转到secondviewcontroller,然后从secondviewcontroller转到thirdviewcontroller

我想从thirdviewcontroller返回到fristviewcontroller。

2 个答案:

答案 0 :(得分:8)

使用以下代码:

    [self.navigationController popToRootViewControllerAnimated:YES];

也可以移动到导航层次结构中的任何特定viewController,您可以在代码下面使用:

[self.navigationController popToViewController:<#(UIViewController *)#> animated:<#(BOOL)#>];

答案 1 :(得分:2)

- (IBAction)GoFirstView:(id)sender
{
    for (UIViewController *controller in self.navigationController.viewControllers)
    {
        if ([controller isKindOfClass:[Firstviewcontroller class]])
        {
            //Do not forget to import Firstviewcontroller.h

            [self.navigationController popToViewController:controller animated:YES];
            break;
        }
    }
}