【知识总结】退出控制器的几种方式

一,pop退出方式

2,pop到指定的控制器:

  • 2.1通过获取 navigationController 获取到指定控制器i,然后 pop 到指定控制器
UIViewController *targetVc = [self.navigationController.childViewControllers objectAtIndex:self.navigationController.childViewControllers.count - 4];
[self.navigationController popToViewController:targetVc animated:YES];
  • 2.2 通过循环判断,找到指定类型的控制器,进行跳转
// 找到指定控制器
- (AGDemandDetailViewController *)getRootViewController{
    AGDemandDetailViewController *rootViewController = nil;
    for (UIViewController *vc in self.navigationController.viewControllers) {
        if ([vc isKindOfClass:[AGDemandDetailViewController class]]) {
            rootViewController = (AGDemandDetailViewController *)vc;
            break;
        }
    }
    return rootViewController;
}

// pop 到指定控制器
[self.navigationController popToViewController:[self getRootViewController] animated:YES];

你可能感兴趣的:(【知识总结】退出控制器的几种方式)