Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当前一个VC设置setNavigationBarHidden为YES的时候,第二次进入webVC的时候,返回有BUG #5

Open
Regansun opened this issue Jan 7, 2016 · 12 comments

Comments

@Regansun
Copy link

Regansun commented Jan 7, 2016

把当前VC设置setNavigationBarHidden为YES, 然后进入WebViewVC,点返回,页面返回当当前界面,再次进入,再点返回,页面就不会返回了,而且返回按钮也没用了!
//当前VC设置代码

  • (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.delegate = self;
    }

pragma mark - UINavigationControllerDelegate

  • (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (viewController == self) {
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    }else{
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationController.delegate = nil;
    }
    }
    进入同一个webVC两次,就会出现
@Roxasora
Copy link
Owner

Roxasora commented Jan 7, 2016

我复现一下~稍等

@Regansun
Copy link
Author

Regansun commented Jan 8, 2016

问题解决了
//! 如果应该pop,说明是在 popViewController 之后,应该直接 popItems
if (self.shouldPopItemAfterPopViewController) {
self.shouldPopItemAfterPopViewController = NO;
[self popViewControllerAnimated:YES]; //////加上这句就ok了!
return YES;
}

@Roxasora
Copy link
Owner

Roxasora commented Jan 8, 2016

亲,可否把你的demo发给我看一下,这个地方这样设置可能会引起其他的问题。。

@Regansun
Copy link
Author

Regansun commented Jan 8, 2016

我是在你的domo上直接改的,运行了下, 貌似别的地方也没影响

@Regansun
Copy link
Author

Regansun commented Jan 8, 2016

好像是有问题,网页进入多级再返回就不对了

@Regansun
Copy link
Author

Regansun commented Jan 8, 2016

-(BOOL)navigationBar:(UINavigationBar )navigationBar shouldPopItem:(UINavigationItem *)item{
//! 如果不应该 pop,说明是点击了导航栏的返回,这时候则要做出判断区分是不是在 webview 中
if ([self.topViewController isKindOfClass:[RxWebViewController class]]) {
RxWebViewController
webVC = (RxWebViewController*)self.viewControllers.lastObject;
if (webVC.webView.canGoBack) {
[webVC.webView goBack];
//!make sure the back indicator view alpha back to 1
self.shouldPopItemAfterPopViewController = NO;
[[self.navigationBar subviews] lastObject].alpha = 1;
return NO;
}else{
[self popViewControllerAnimated:YES];
return NO;
}
}if (self.shouldPopItemAfterPopViewController) {
//! 如果应该pop,说明是在 popViewController 之后,应该直接 popItems
self.shouldPopItemAfterPopViewController = NO;
return YES;
}else{
[self popViewControllerAnimated:YES];
return NO;
}
}
这样判断的顺序换下,应该可以了/有可能还有问题

@Roxasora
Copy link
Owner

Roxasora commented Jan 8, 2016

webviewController 的naviBar 是你自己设置的是吗? 我看你一开始隐藏了naviBar

@Regansun
Copy link
Author

Regansun commented Jan 8, 2016

是用系统的,在第一个页面设置隐藏了,然后push以后的页面都不隐藏的

@Regansun
Copy link
Author

Regansun commented Jan 8, 2016

好的,已经发你邮箱了

@Regansun
Copy link
Author

之前修改的还是有问题,http://www.jianshu.com/p/6376149a2c4c 参考这个连接的貌似找到了完美解决的办法了

@ynot16
Copy link

ynot16 commented Jul 7, 2017

这个问题有解决方案了么?复现的步骤就像题目说的一样,前一个vc隐藏了导航栏,然后push到另一个没有隐藏导航栏的vc。第一次push,pop是正常的,但是第二次push之后,就pop不了。必现。

@ynot16
Copy link

ynot16 commented Jul 7, 2017

因为是隐藏导航栏出现的问题,我猜是self.shouldPopItemAfterPopViewController的记录出的问题。加了一下代码,貌似解决了
`- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated {
self.shouldPopItemAfterPopViewController = hidden;
[super setNavigationBarHidden:hidden animated:animated];
}

  • (void)setNavigationBarHidden:(BOOL)navigationBarHidden {
    self.shouldPopItemAfterPopViewController = navigationBarHidden;
    [super setNavigationBarHidden:navigationBarHidden];
    }`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants