-3

For some days now I have been suffering with UITabBarItems.

I have done my application in programatical way, not using Interface Builder. I have both a UINavigationBar and a UITabbarController.

From home page when I have proceed with navigation (I mean when I move to next page) at that time when i have clicked next tab item (Contact), and again when I have clicked the home button, it is not moving to home page, it is remaining with the previous page where I left that one, it is not redirecting to home page at all,

I have placed the UITabbarController-code in my application delegate:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.tabBarController = [[UITabBarController alloc] init];
viewController *vc = [[viewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vc];
[navController.tabBarItem setTitle:@"Home"];
[navController.tabBarItem setImage:[UIImage imageNamed:@"home.png"]];

viewController1 *vc1 = [[viewController1 alloc] init];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:vc1];
[navController1.tabBarItem setTitle:@"Contact"];
[navController1.tabBarItem setImage:[UIImage imageNamed:@"contact.png"]];

viewController2 *vc2 = [[MapViewController alloc] init];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:vc2];
[navController2.tabBarItem setTitle:@"Info"];
[navController2.tabBarItem setImage:[UIImage imageNamed:@"info.png"]];

NSArray *viewControllers = [NSArray arrayWithObjects:navController, navController1,navController2,  nil];
 _tabBarController.delegate = self;
[_tabBarController setViewControllers:viewControllers];

[self.window setRootViewController:_tabBarController];
[self.window makeKeyAndVisible];
 return YES;

I didn't used these methods:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item 

Please give me suggestions, or something that may be useful to me.

Emil
  • 7,220
  • 17
  • 76
  • 135
  • I am unsure I understand your question because of the way you have put it. Can you simplify it for me? What do you want? – Popeye Jun 21 '12 at 12:06
  • Is this not the same as a question you have already asked? Being unable-to-set-action-for-uitabbaritem-programmatically. I believe you have made a duplicate of your own question. – Popeye Jun 21 '12 at 12:12
  • i got tabbar's, now i got another problem,so i have asked again – IPhone Developer Jun 21 '12 at 12:18
  • repost of [Unable to set action for UITabbarItem Programmatically](http://stackoverflow.com/questions/10926391/unable-to-set-action-for-uitabbaritem-programmatically) – jscs Jun 21 '12 at 19:06

1 Answers1

0

Default behaviour of UITabbarController is, that if you tap a tab and this tab contains a navigationcontroller, you get the page which is on top of the navigationcontrollers viewcontroller-stack.

To avoid this you have to popToRootViewController when you tap on the tab.

If you implement

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
 {
    [viewController.navigationController popToRootViewControllerAnimated:NO];
 }

it should do the trick.

rene
  • 41,474
  • 78
  • 114
  • 152
Maverick1st
  • 3,774
  • 2
  • 34
  • 50