// 返回跟控制器
[self.navigationController popToRootViewControllerAnimated:YES];
// 从导航push过去的视图想要返回指定控制器时可以使用以下方法
// 第一种:
//objectAtIndex后面的参数就是你想要返回的控制器在navigationController.viewControllers的下标
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES]
// 第二种:
//UIViewController是指定的要返回的控制器
for (UIViewController *controller in self.navigationController.viewControllers) {
if ([controller isKindOfClass:[UIViewController class]]) {
[self.navigationController popToViewController:controller animated:YES];
}
}
//切记:不可使用如下方法会导致崩溃
UIViewController *VC = [[UIViewController alloc] init];
[self.navigationController popToViewController:VC animated:YES];
// 崩溃信息如下:
//Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist.'
网友评论