1. 获取到所有的控制器的数组,当页面跳转到C页面的时候,就将B页面从数据中移除掉,这样点击返回按钮的时候,页面直接就跳转到了A页面。
- (void)back {
NSMutableArray *vcArr = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
[vcArr removeObjectAtIndex:vcArr.count-2]; // 将上级页面从数组中移除
self.navigationController.viewControllers = vcArr;
[self.navigationController popViewControllerAnimated:YES];
}
2. 直接在控制器数组中找到想要跳转的那个控制器所在的位置,获取到该控制器,然后进行pop
NSInteger num = self.navigationController.viewControllers.count;
if (num > 3) {
UIViewController *popVC = self.navigationController.viewControllers[num - 3];
[self.navigationController popToViewController:popVC animated:YES];
}
3. 在C页面定义Block,当点击返回调用Block事件,在Block里面写返回事件
typedef void(^BackBlock)(void);
@property (nonatomic, copy) BackBlock backBlock;
- (void)back {
[self.navigationController popViewControllerAnimated:NO];
__weak typeof(self) weakSelf = self;
weakSelf.backBlock();
}
B.m:
C_Controller *vc = [[C_Controller alloc] init];
vc.backBlock = ^(){
[self.navigationController popViewControllerAnimated:NO];
};
[self.navigationController pushViewController:vc animated:YES];
4.
for (UIViewController *vc in self.navigationController.viewControllers) {
if ([vc isKindOfClass:[MineViewController class]]) {
[self.navigationController popToViewController:vc animated:YES];
}
}
5.
[self.navigationController pushViewController:vc animated:YES];
UINavigationController *nav = self.navigationController;
UIViewController *root = nav.viewControllers[0];
nav.viewControllers = @[root,vc];