在我的app
我有三个uiviewcontroller
:firstviewcontroller,secondviewcontroller和thirdviewcontroller。
我使用navigationcontroller从firstviewcontroller转到secondviewcontroller,然后从secondviewcontroller转到thirdviewcontroller
我想从thirdviewcontroller返回到fristviewcontroller。
答案 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;
}
}
}