方法一:
- (void)backToAppointedController1 {
// 直接查找你需要跳轉(zhuǎn)的界面 不會算的話自己從1開始試吧 、此法需要知道你返回到的控制器的位置
UIViewController *viewC = [self.navigationController.viewControllers objectAtIndex:index];
[self.navigationController popToViewController:viewC animated:YES];
}
方法二:
- (void)backToAppointedController2 {
// 此法只需要知道你需要返回的控制器的類名稱即可
UINavigationController *navC = self.navigationController;
NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
for (UIViewController *vc in navC.viewControllers) {
[viewControllers addObject:vc];
if ([vc isKindOfClass:[YourController Class]]) {
break;
}
}
if (viewControllers.count == navC.viewControllers.count) {
[self.navigationController popViewControllerAnimated:YES];
}
else {
[navC setViewControllers:viewControllers animated:YES];
}
}
方法三:將中間控制器刪除
- (void)backToAppointedController3 {
//得到當(dāng)前視圖控制器中的所有控制器
NSMutableArray *array = [self.navigationController.viewControllers mutableCopy];
//把B從里面刪除
[array removeObjectAtIndex:1];
//把刪除后的控制器數(shù)組再次賦值
[self.navigationController setViewControllers:[array copy] animated:YES];
}