controlling tabbar items

Discussion in 'iOS Programming' started by sujithkrishnan, Aug 27, 2008.

  1. macrumors 6502

    Joined:
    May 9, 2008
    Location:
    Bangalore
    #1
    Hi

    In my app, i am having tabBarController , whose view is added to window's subview.

    CODE is like as follows...

    Code:
    FirstViewController *first = [[FirstViewController alloc]init];
    	SecondViewController *second = [[SecondViewController alloc]init];
    	ThirdViewController *third   = [[ThirdViewController alloc]init];
    	
    	UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:first];
    	UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:second];
    	UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:third];
    	[first release];
    	[second release];
    	[third release];
    	
     	tabBarController = [[UITabBarController alloc]init];
    	[tabBarController setViewControllers:[NSArray arrayWithObjects:nav1,nav2,nav3,nil] animated:YES];
    	[nav1 release];
    	[nav2 release];
    	[nav3 release];
    	[window addSubview:[tabBarController view]];
    	[window makeKeyAndVisible];
    
    

    Here in one of my controller , i am having a button added to its view.
    On clicking that button i want to re arrange the tabBar

    For eg: If user touch that Button, my tabBar should contains only two items, say second View Controller and thirdViewController.

    I tried it with setting viewControllers of the tabBarController

    On click of Buttoon in firstViewController... i will call as follows
    Code:
    sampleTabBarAppDelegate *sample = [[UIApplication sharedApplication] delegate];
    [sample changeStyleToTwoItems];
    
    
    Following is the method which i call ....

    Code:
    -(void)changeStyleToTwoItems
    {
    SecondViewController *second = [[SecondViewController alloc]init];
    	ThirdViewController *third   = [[ThirdViewController alloc]init];
    	
    	UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:second];
    	UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:third];
    	[second release];
    	[third release];
    	
     	tabBarController = [[UITabBarController alloc]init];
    	[tabBarController setViewControllers:[NSArray arrayWithObjects:nav2,nav3,nil] animated:YES];
    	[nav2 release];
    	[nav3 release];
    	[window addSubview:[tabBarController view]];
    	[window makeKeyAndVisible];
    }
    
    The thing is that it is working and removing teh old tabBar with new one... But teh new one is not responding....
     

Share This Page