I am trying to do the following.
I have a tab bar controller with 2 tabs in it. Both the tabs are navigation controller with a table view on each of them.
Now when I select one cell of the table in the first tab, I am pushing another tab bar controller, so I would like to hide the tab bar of the parent tabbarcontroller, and when I click the back button on the navigation bar I would like to see the the parent tab bar again, as I am in my parent tab bar view.
I tried hidesbottombarwhenpushed and it hides the parent tab bar controller tab bar but when I click back it doesn't brings it back.
The accepted answer had a problem to me.
My app had a navigation with the depth of three UIViewController.
The solution for me was setting the delegate of UINavigationControllerDelegate
swift:
self.navigationController?.delegate = self
Objective-c:
self.navigationController.delegate = self;
And then implement the following delegate method
Swift:
fun navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if fromVC.isKindOfClass(FirstViewController) && toVC.isKindOfClass(SecondViewController) {
self.hidesBottomBarWhenPushed = true;
}
else if fromVC.isKindOfClass(SecondViewController) && toVC.isKindOfClass(FirstViewController) {
self.hidesBottomBarWhenPushed = false;
}
return nil
}
Objective-c:
-(id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController*)fromVC
toViewController:(UIViewController*)toVC
{
if ([fromVC isKindOfClass:[FirstViewController class]] && [fromVC isKindOfClass:[SecondViewController class]]) {
self.hidesBottomBarWhenPushed = true;
}
else if ([fromVC isKindOfClass:[SecondViewController class]] && [fromVC isKindOfClass:[FirstViewController class]]) {
self.hidesBottomBarWhenPushed = false;
}
return nil;
}
Hope it helped.
Ok, So finally I got my answer, this is what I am suppose to do.
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:aViewController animated:YES];
self.hidesBottomBarWhenPushed=NO;
So basically hidesBottomBarWhenPushed = YES, and then push your view controller and then hidesBottomBarWhenPushed = NO; this works like a charm.
Thanks to eddy and his post here
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