I am working on a tabbar application with 3 tabs in it.
I have created a UITabBarController
with 3 UINavigationController
with their respected RootViewControllers which is working perfectly fine.
Now I have a Home button in all of my views. When I click on it suppose to display a HomeView
(Which is not the RootViewController
of first UINavigationController
) with no tabs selected.
Can any one help me with this?
I have tried most of the links related to how to deselect all the tabs of UITabBarController
but none of it had the perfect answer..!!
Here is my code:
-(void)setViews
{
viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
UIViewController *viewController3 = [[[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil] autorelease];
viewController4 = [[CalculatorsView alloc] initWithNibName:@"CalculatorsView" bundle:nil];
navigationController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
[navigationController1.navigationBar setBackgroundImage:[UIImage imageNamed:@"title-bar.png"] forBarMetrics:UIBarMetricsDefault];
UINavigationController *navigationController2=[[[UINavigationController alloc]initWithRootViewController:viewController2] autorelease];
[navigationController2.navigationBar setBackgroundImage:[UIImage imageNamed:@"title-bar.png"] forBarMetrics:UIBarMetricsDefault];
UINavigationController *navigationController3=[[[UINavigationController alloc]initWithRootViewController:viewController3] autorelease];
[navigationController3.navigationBar setBackgroundImage:[UIImage imageNamed:@"title-bar.png"] forBarMetrics:UIBarMetricsDefault];
UINavigationController *navigationController4=[[[UINavigationController alloc]initWithRootViewController:viewController4] autorelease];
[navigationController4.navigationBar setBackgroundImage:[UIImage imageNamed:@"title-bar.png"] forBarMetrics:UIBarMetricsDefault];
[navigationController1.navigationBar setHidden:YES];
[navigationController2.navigationBar setHidden:YES];
[navigationController3.navigationBar setHidden:YES];
[navigationController4.navigationBar setHidden:YES];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"tabbar-0.png"];
[[[self tabBarController]tabBar]setSelectionIndicatorImage:[UIImage imageNamed:@"transparent.png"]];
[self.tabBarController setDelegate:self];
self.tabBarController.viewControllers = @[navigationController1, navigationController2,navigationController3];
appDelegate.window.rootViewController = self.tabBarController;
}
#pragma mark TABBAR DELEGATE
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if (tabBarController.selectedIndex == 0)
{
self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"tabbar-1.png"];
[self.navigationController1 setViewControllers:@ [viewController4] animated:NO];
}
else if (tabBarController.selectedIndex == 1)
{
self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"tabbar-2.png"];
}
else if (tabBarController.selectedIndex == 2)
{
self.tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"tabbar-3.png"];
}
}
Can any body tell me that its even possible to unselect all tabs?