In my tab based app, I programetically created the tabbar app with 4 tabs. In my first tab there is 5 scrren & in 3rd tab there is 3 screens.
On my first tab's 2nd screen when i click one button i want it should go to 2nd screen in 3rd tab. But now it go to the screen which is last open on 3rd tab.
e.g. tabControllers: a,b,c,d
a tab: 1->2>3>4>5
C tab: 1>2>3
I want selected tab is a: & screen is: 3 &
click button on that screen go to
selected tab is C & screen is 2nd
reference link is: Change the selected TabBar index on button click
My code is as follow:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//for home tab..
UINavigationController *nav1 = [[UINavigationController alloc] init];
UIViewController *viewController1 = [[[CarAccidentAppViewController alloc] initWithNibName:@"CarAccidentAppViewController_iPhone" bundle:nil] autorelease];
nav1.viewControllers = [NSArray arrayWithObjects:viewController1, nil];
//for steps tab...
UINavigationController *nav2 = [[UINavigationController alloc] init];
UIViewController *viewController2 = [[[FirstSteps alloc] initWithNibName:@"FirstSteps" bundle:nil] autorelease];
nav2.viewControllers = [NSArray arrayWithObjects:viewController2, nil];
//for profiles tab...
UINavigationController *nav3 = [[UINavigationController alloc] init];
UIViewController *viewController3 = [[[Profiles alloc] initWithNibName:@"Profiles" bundle:nil] autorelease];
nav3.viewControllers = [NSArray arrayWithObjects:viewController3, nil];
//for contact us tab...
UINavigationController *nav4 = [[UINavigationController alloc] init];
UIViewController *viewController4 = [[[ContactUs alloc] initWithNibName:@"ContactUs" bundle:nil] autorelease];
nav4.viewControllers = [NSArray arrayWithObjects:viewController4, nil];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4 ,nil];
self.window.rootViewController=self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
//Button click event
-(IBAction)btnNewDriverPressed:(id)sender
{
[[NSUserDefaults standardUserDefaults]setInteger:0 forKey:@"showselectedIndex"];
self.tabBarController.selectedViewController=[self.tabBarController.viewControllers
objectAtIndex:2];
}