pop返回的四种方式

  • 直接返回上一层
[self.navigationController popViewControllerAnimated:YES];
  • 回到根控制器
 [self.navigationController popToRootViewControllerAnimated:YES];
  • 通过Index返回(从根控制以后算起 1,2,3...)
比如说rootVC->test1VC->test2VC->test3VC
在test3VC 中objectAtIndex:1 代表 test3VC->test1VC
    [self.navigationController   popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
  • 通过类返回指定控制器(XXXViewController需要返回的控制器)
  for (UIViewController *VC in self.navigationController.viewControllers) {
        
        if ([VC isKindOfClass:[XXXViewController class]]) {
            
            [self.navigationController popToViewController:VC animated:YES];
        }
    }

你可能感兴趣的:(pop返回的四种方式)