之前在导航控制器的基类中push隐藏tabbar的写法:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (self.viewControllers.count > 0) {
viewController.hidesBottomBarWhenPushed = YES;
} else {
viewController.hidesBottomBarWhenPushed = NO;
}
[super pushViewController:viewController animated:animated];
}
改成如下:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (self.viewControllers.count > 0) {
// 当前导航栏, 只有一个viewController push的时候设置隐藏
if (self.viewControllers.count == 1) {
viewController.hidesBottomBarWhenPushed = YES;
}
} else {
viewController.hidesBottomBarWhenPushed = NO;
}
[super pushViewController:viewController animated:animated];
}
这样就行了。