正常情况下还A跳转B,B跳转C。
有些时候我们需要A直接跳转C,C返回B,B返回A。
下面有2种处理方式,供大家用的爽。
PUSH 大法跳转式
- 下面的代码,是在C控制器里的。场景是:A跳转到C,C在自己的页面生成B控制器,然后插入到navigation里。返回的时候,就到了B控制器,B返回就到了A。
B *b = [[B alloc]init];
NSArray *tempArray = self.navigationController.viewControllers;
NSMutableArray *tempmu = [NSMutableArray arrayWithArray:tempArray];
[tempmu insertObject:twc atIndex:1];
PRESENT模态弹出 大法跳转式
- 下面的代码,是写在A控制器里,利用模态弹出C控制器
C *cVc = [[C alloc]init];
WYBaseNavgationController *nav = [[WYBaseNavgationController alloc]initWithRootViewController:cVc];
[self presentViewController:nav animated:YES completion:^{
B *bVc = [[B alloc]init];
[self.navigationController pushViewController:bVc animated:YES];
}];
- 下面的代码,是写在C控制器里,多写了个关闭弹出视图的方法.点击关闭C控制器按钮,就到了B控制器,点击B返回,就到了A控制器。
-(void)initLeftBarButtonItem{
//隐藏原生返回按钮
self.navigationItem.hidesBackButton = YES;
UIButton *backButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
//按钮偏移
backButton.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
[backButton setImage:[UIImage imageNamed:@"back_black"] forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(clickLeftBtnDisMiss) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView: backButton];
self.navigationItem.leftBarButtonItem = leftItem;
}
-(void)clickLeftBtnDisMiss{
[self dismissViewControllerAnimated:YES completion:nil];
}