当状态恢复时 hidesBottomBarWhenPushed = YES 时,导航控制器不隐藏标签栏

Ben*_*air 5 objective-c uikit ios

我在恢复视图控制器的状态时遇到问题,hidesBottomBarWhenPushed=YES在 UINavigationController 中推送放置在 UITabBarController 中。

发生的事情基本上是 UINavigationController 堆栈被恢复并且正确的控制器在屏幕上,但是该控制器不尊重 hidesBottomBarWhenPushed。

我想出的唯一可行的 hack 是 viewDidAppear 上的快速选项卡切换,使 TabBar 消失,因为它应该在设置 hidesBottomBarWhenPushed 时发生:

- (void)_fixTabBarStateRestorationBug {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSInteger currentTab = (NSInteger)self.tabBarController.selectedIndex;
        self.tabBarController.selectedIndex = abs(currentTab - 1);
        self.tabBarController.selectedIndex = currentTab;
    });
}
Run Code Online (Sandbox Code Playgroud)

Ben*_*son 5

这绝对是一个iOS错误。上面的解决方案对我来说不是开箱即用的,但是如果你把它放在标签栏控制器的viewDidAppear方法中,那就可以了:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    NSInteger currentTab = (NSInteger)self.tabBarController.selectedIndex;
    self.tabBarController.selectedIndex = abs(currentTab - 1);
    self.tabBarController.selectedIndex = currentTab;
});
Run Code Online (Sandbox Code Playgroud)

如果将它放在viewDidAppear选项卡中视图控制器的视图控制器中,您将创建一个无限循环。在那个原因中使用问题中提到的一次性令牌方法。