iOS 开发之返回当前视图控制器堆栈里的某个控制器
/**
确定
*/
- (void)clickConfirmBtn {
HomeVC *homeVC = [[HomeVC alloc] init];
[self popToViewController:homeVC];
}
/**
返回当前视图控制器堆栈里的某个控制器
@param targetViewController 目标控制器
*/
- (void)popToTargetViewController:(UIViewController *)targetViewController {
UIViewController *targetVC = nil;
// 遍历 ViewController
for (UIViewController * viewController in self.navigationController.viewControllers) {
// 这里判断是否为你想要跳转的页面
if ([viewController isKindOfClass:[targetViewController class]]) {
targetVC = viewController;
}
}
if (targetVC) {
// 跳转
[self.navigationController popToViewController:targetVC animated:YES];
}
}