点击tabBar时转到rootView [英] Go to rootView when tabBar tapped

查看:108
本文介绍了点击tabBar时转到rootView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了基于视图的应用程序&在那我以编程方式生成TabBar。
问题是:

I used view based app & in that i programmatically generate TabBar. Problem is:

我有一个Iphone应用程序,我有2个tabitems和tabbarcontroller.Inside tabbarcontroller每个viewcontroller是一个导航控制器。当选择第二个选项卡我有一个视图控制器。当我选择一个按钮时,我正在将另一个视图控制器推送到self.navigation控制器。在那个视图控制器中,我正在推动并去那样。但问题是当我再次选择tabitem时那个pushviewcotrooller在那里显示。但是当我选择选项卡时,我再次需要rootview

I have an Iphone application in which i have 2 tabitems with a tabbarcontroller.Inside the tabbarcontroller each viewcontroller is a navigation controller.when selecting the second tab i have a view controller.when selecting a button on that i am pushing another view controller to the self.navigation controller.and in that viewcontroller i am pushing and go like that.But the problem is when i am selecting the tabitem again that pushedviewcotrooller is shown there.but i need that rootview there again when i am selecting the tab

我在AppDelegate.m中的代码是:

my code in AppDelegate.m is:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

 UINavigationController *nc1;
    nc1 = [[UINavigationController alloc] init];

UIViewController *viewController1 = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    nc1.viewControllers = [NSArray arrayWithObjects:viewController1, nil];





    UINavigationController *nc2;
    nc2 = [[UINavigationController alloc] init];

 UIViewController *viewController2 = [[[secondview alloc] initWithNibName:@"secondview" bundle:nil] autorelease];
    nc2.viewControllers = [NSArray arrayWithObjects:viewController2, nil];


    self.tabBarController = [[[UITabBarController alloc] init] autorelease];
   self.tabBarController.viewControllers = [NSArray arrayWithObjects:nc1,nc2,nil];
  self.window.rootViewController=self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}


推荐答案

可能你在寻找这个:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{       
    int tabitem = tabBarController.selectedIndex;
    [[tabBarController.viewControllers objectAtIndex:tabitem] popToRootViewControllerAnimated:YES];
}

这篇关于点击tabBar时转到rootView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆