用导航控制器返回到上一页和返回到根控制器有其自带方法。
返回到特定的控制器的核心代码:
popToViewController用法
方式一,不推荐
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];
方式二,推荐
或(推荐下面这种,不受后期控制器数量影响)
for (UIViewController *controller in self.navigationController.viewControllers) {
if ([controller isKindOfClass:[你要跳转到的Controller class]]) {
[self.navigationControllerpopToViewController:controller animated:YES];
}
}
方式三,推荐 这种方式适合返回指定控制器并调用其方法(比如刷新)
// 需要返回调用的
MyIMPPlanController *myIMPVC = nil;
for (int i = 0; i < self.navigationController.viewControllers.count; i++) {
CustomViewController *cv = self.navigationController.viewControllers[i];
if ([cv isKindOfClass:[MyIMPPlanController class]]) {
myIMPVC = (MyIMPPlanController *)cv;
break;
}
}
[self.navigationController popToViewController:myIMPVC animated:YES];
[myIMPVC refreshData];