tags:

views:

1170

answers:

2

Hi,

I have an application that has a tabBar that handles all the views. In the first view I have a login process. When that process finishes I want to go automatically to the second tabBar view without making the user to click in its respective tabBar button.

All I've got until now is to highlight the button with this:

myTabBar.selectedItem = [myTabBar.items objectAtIndex:1];

But I have no idea about how to bring the second view related to that button to the front, automatically. Until now the user has to press the button when it gets lighted (selected).

Any idea about how to do this? Is it possible? It would be much appreciated. Thanks.

A: 

Use the selectedViewController or selectedIndex methods of the corresponding UITabBarController.

In response to the comments on this answer, I have provided an example of how this might be accomplished:

id firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstView" bundle:[NSBundle mainBundle]];
id secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:[NSBundle mainBundle]];

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:firstViewController, secondViewController, nil];

[firstViewController release];
[secondViewController release];

// Select the second tab bar item and its view
self.tabBarController.selectedIndex = 1;

[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];

In my testing, it seems that using the selectedViewController method of UITabBarController to set the current view does not update the selectedIndex property (the new view is displayed but the selected UITabBarItem is not changed). This is in contrast to the behavior promised in the documentation. Using the selectedIndex method as demonstrated in the code snippet above should work fine, however.

titaniumdecoy
Sorry, I'm quite lost with this. I've tried these:rootController.selectedIndex = 1;rootController.selectedViewController.tabBarItem = [myTabBar.items objectAtIndex:1];...where the rootController is the UITabBarController, and none of them work... could you tell me how to use this methods for getting what I want? Thanks.
This, that makes more sense, doesn't work either:self.rootController.selectedViewController = [self.rootController.viewControllers objectAtIndex:1];Any clue about what am I doing wrong?
Either this...PickersAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; self.rootController.selectedViewController = delegate.navController;It seems that selectedViewController doesn't work for my controller :-S
Are you sure the UITabBarController is linked to the UITabBar in question (via its tabBar property)?
titaniumdecoy
Thanks for the reply but it didn't work for me. Maybe the problem is that thing about the tabBar property, but Idon't know what do you mean exactly... I have two viewControllers linked to the first and thir button of the tabBar and a navController linked to the second one (the one I want to activate automatically) I don't see why theselectedIndex method doesn't work for my rootController (tabBar controller). Something missing in IB do you think? I have no idea about what's going one
A: 

Hi,

Finally I got the solution here:

http://stackoverflow.com/questions/677651/iphone-sdk-set-focus-to-different-tabbar-view-on-button-click-from-first-tabbar

Thanks anyways.

That's exactly what I suggested: tabController.selectedIndex = 1;
titaniumdecoy