之前在项目时,也遇到该问题,当时是自己写了一个假的导航条,用View代替,现在找到一个更好的方法,不用傻傻的写一个View,直接上代码。
如图
A-->C
HYNCController *manageVC = [[HYNCController alloc] init];
manageVC.isNavPush = @"0";
HYNNavigationController *nav = [[HYNNavigationController alloc] initWithRootViewController:manageVC]; [self presentViewController:nav animated:NO completion:^{ }];
B-->C
HYNCController *manageVC = [[HYNCController alloc] init];
manageVC.isNavPush = @"1";
[self.navigationController pushViewController:manageVC animated:YES];
C
.h (nonatomic, copy) NSString *isNavPush;//没有导航条页面进入为0,其他为1
.m 返回按钮中
if([_isNavPush isEqualToString:@"0"]){
[self dismissViewControllerAnimated:NO completion:^{ }]; }else{ [self.navigationController popViewControllerAnimated:YES]; }- (void)viewWillAppear:(BOOL)animated
{ [super viewWillAppear:animated]; //隐藏导航条 self.navigationController.navigationBar.hidden = YES;}
//上滑时 出现导航条
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{ if(_tbView.contentOffset.y >40){ self.navigationController.navigationBar.hidden = NO; }else{ self.navigationController.navigationBar.hidden = YES; } }//判断当前ViewController是push还是present方式显示的
//通过判断self有没有present方式显示的父视图presentingViewController- (void)senderClick:(UIButton *)sender { if (self.presentingViewController) { [self dismissViewControllerAnimated:YES completion:nil]; } else { [self.navigationController popViewControllerAnimated:YES]; }}//通过判断self.navigationController.viewControllers的最后一个是否是当前控制器,或者self.navigationController.topViewController == self- (void)senderClick:(UIButton *)sender { if (self.navigationController.topViewController == self) { [self.navigationController popViewControllerAnimated:YES]; } else { [self dismissViewControllerAnimated:YES completion:nil]; }}