我最近已经解决了这个,我发现,这是需要调用setNavigationBarHidden:NO
pushViewController:
和setNavigationBarHidden:YES
后立即popViewController:
后,在每次调用动画YES。
所以,当推:
[nc pushViewController:classBView animated:YES]
[nc setNavigationBarHidden:NO animated:YES]
和弹出时:
[nc popViewControllerAnimated:YES]
[nc setNavigationBarHidden:YES animated:YES]
但在我的情况下,而我所能做的如上推,我不想改变我的类B,而是希望它不知道导航栏以前没有隐藏(因为它不是我的代码)。此外,使用普通的“后退”按钮弹出该视图,但没有明确调用popViewControllerAnimated:
。在我的代码中最好的工作是让我的类A成为UINavigationController
委托,并在发生弹出时将工具栏隐藏在委托方法调用中。
不幸的是我发现UINavigationControllerDelegate
方法是不是太有帮助,willShowViewController
& didShowViewController
推我B类角度还是从另外一个,它已经弹出推回它时,当被称为无差别。
我在 https://stackoverflow.com/questions/642312/中关于覆盖UINavigationController
的建议,我做了一些自定义的委托方法,其中一个在[super popViewControllerAnimated:]
之后被调用。我的子类可在https://gist.github.com/jpmhouston/6118713和委托方法是:
- (void)navigationController:(UINavigationController *)navigationController isPoppingViewController:(UIViewController *)poppedViewController backTo:(UIViewController *)revealedViewController {
if (revealedViewController == self && [poppedViewController isKindOfClass:[MyClassB class]]) {
[navigationController setNavigationBarHidden:YES animated:YES];
// ...and more code to run only when going from class B back to class A
}
}
我敢肯定有更简单的方法有setNavigationBarHidden:
称为继按下后退按钮,但这个工作对我来说。
[self.navigationController setNavigationBarHidden:NO];也可以在viewWillAppear中设置此行。 – 2012-10-23 10:12:20
你想要显示哪种颜色? – TheTiger