0

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];
}
4

2 回答 2

0

请上传您的流程,并附上说明您真正想要实现的目标的图片。

浏览您的愿望viewcontroller/screen使用initwithnibname方法。

跟随 :

self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
[self.navigationController pushViewController:self.viewController animated:YES];
于 2012-09-19T11:22:23.850 回答
0

抱歉,您无法使其工作..如果您在第一个屏幕的“C”选项卡中,您只需单击任何按钮即可进入第二个屏幕。通过按 c 选项卡,它不会在不按任何按钮的情况下将第二个视图控制器加载到您的导航控制器。所以你需要自己推到第二个屏幕并选择c选项卡。但我认为,如果你这样做,你的应用程序设计并不好。它不会提供最佳的用户体验。

于 2012-09-19T11:44:50.380 回答