I have a problem restoring state for view controller with hidesBottomBarWhenPushed=YES
pushed in UINavigationController that placed within UITabBarController.
What happens is basically the UINavigationController stack is restored and the right controller is on screen, but hidesBottomBarWhenPushed is not respected for that controller.
The only viable hack I came up with is the fast tab switch on viewDidAppear to make TabBar disappear as it supposed to happen if hidesBottomBarWhenPushed set:
- (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;
});
}
This is definitely an iOS bug. Solution above didn't work out-of-the-box for me, but this did if you put this in the tab bar controller's viewDidAppear
method:
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;
});
If you put this in the view controllers viewDidAppear
for a view controller in a tab you will create an infinite loop. In that cause use the once token approach mentioned in the question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With