Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

show/hide the tabbar when needed from a view controller

Tags:

xcode

ios

ipad

i am new to iOS programming. i really need your help.

i have a login screen that takes me to a map (google API). on clicking any created annotation i want to load a tabbar with 2 views.

i searched and found out that i need to add the tabbar at the starting ie the appdelegate and show/hide the tabbar when needed.

so i made 2 functions to show and hide tabbar as

-(void)Load_tabBar{
[self.navigationController.view removeFromSuperview];
[self.window addSubview:tabBarController.view];
[self.window makeKeyWindow];}

-(void)remove_tabBar{
self.tabBarController.selectedIndex=0;
[self.tabBarController.view removeFromSuperview];
[self.window addSubview:navigationController.view];
[self.window makeKeyWindow];}

it did work when i call the Load_tabBar method and when i click back it calls remove_tabBar method. if i again call Load_tabBar method and back, it crashes giving error

-[UILayoutContainerView window]: message sent to deallocated instance 0x563b0b0

edited: PS : can i add tabbar view to a view controller and then push that view?

thnx

like image 522
Anshuk Garg Avatar asked Feb 06 '12 11:02

Anshuk Garg


People also ask

How do I show the bottom bar in Swift?

Answer: Use self. tabBarController?. tabBar. hidden instead of hidesBottomBarWhenPushed in each view controller to manage whether the view controller should show a tab bar or not.

What is tabBar controller?

The tab bar interface displays tabs at the bottom of the window for selecting between the different modes and for displaying the views for that mode. This class is generally used as-is, but may also be subclassed. Each tab of a tab bar controller interface is associated with a custom view controller.


3 Answers

This method definitely works. You just need to put it in the method BEFORE you push it, like this:

-actionThatPushTheViewController { 

    //create the view controller here, do some init. 

    //then:
    theViewControllerToBePushed.hidesBottomBarWhenPushed = YES;

    //push it here like this: 
    [self.navigationController pushViewController:theViewControllerToBePushed animated:YES];
like image 25
horacex Avatar answered Oct 05 '22 13:10

horacex


use this self.hidesBottomBarWhenPushed = YES;

like image 84
Tendulkar Avatar answered Oct 05 '22 15:10

Tendulkar


I hope this two methods may help you,

- (void) hideTabBar:(UITabBarController *) tabbarcontroller {

int height = 480;

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];

for(UIView *view in tabbarcontroller.view.subviews) {
    if([view isKindOfClass:[UITabBar class]]) {
        [view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
    } 
    else {
        [view setFrame:CGRectMake(view.frame.origin.x,view.frame.origin.y, 320, 436)];
    }
}
[UIView commitAnimations];

}

- (void) showTabBar:(UITabBarController *) tabbarcontroller {

int height = 480;

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; 

for(UIView *view in tabbarcontroller.view.subviews) {

    if([view isKindOfClass:[UITabBar class]]) {
        [view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];            
    } 
    else {
        [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)];
    }
}    

[UIView commitAnimations];

}

Just put this two methods in AppDelegate class and call it where ever required as per you requirement.

like image 25
Nilesh Kikani Avatar answered Oct 05 '22 13:10

Nilesh Kikani