如何在Ios中推送rootviewcontroller

时间:2013-08-09 15:56:58

标签: ios objective-c uinavigationcontroller uitabbarcontroller

我从rootviewController(UInavigation控制器)推送新的StatusViewController(我在程序中创建了UITabbarViewController)。现在,我想点击注销按钮,它按下rootviewcontroller,但我使用下面的代码,它推rootviewcontroller很好,但它仍然在底部的tabbar。

此代码调用rootviewcontroller:

    LoginTab *loginView = [[LoginTab alloc] init];
    [self.navigationController pushViewController:loginView animated:YES];
    [loginView release];

此代码在StatusViewController中创建了UItabbarcontroller:

self.tab=[[UITabBarController alloc]init];

UploadTab *uploadview=[[UploadTab alloc]initWithNibName:nil bundle:nil];
UINavigationController *uploadTabItem = [[[UINavigationController alloc] initWithRootViewController: uploadview] autorelease];
uploadview.title=@"Uploading";
uploadview.tabBarItem.image=[UIImage imageNamed:@"Uploading.png"];
self.title = @"FirstViewControllerTitle";

//SecondViewController
ConvertTab *convertView=[[ConvertTab alloc]initWithNibName:nil bundle:nil];
UINavigationController *convertTabItem = [[[UINavigationController alloc] initWithRootViewController: convertView] autorelease];
convertView.title=@"Convert";
convertView.tabBarItem.image=[UIImage imageNamed:@"Convert.png"];

//ThirdViewController
CompletedTab *completedView=[[CompletedTab alloc]initWithNibName:nil bundle:nil];
UINavigationController *completedTabItem = [[[UINavigationController alloc] initWithRootViewController: completedView] autorelease];
completedView.title=@"Completed";
completedView.tabBarItem.image=[UIImage imageNamed:@"Completed.png"];
UIBarButtonItem * LogoutItem= [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Logout.png"] style:UIBarButtonItemStylePlain target:self action:@selector(logout)];

self.navigationItem.rightBarButtonItem = LogoutItem;
self.tab.viewControllers=[NSArray arrayWithObjects:uploadTabItem,convertTabItem, completedTabItem, nil];

// [self.view insertSubview:self.tab.view belowSubview: uploadview.view];
[self presentModalViewController:self.tab animated:NO];

你可以看到这个图片: enter image description here

2 个答案:

答案 0 :(得分:3)

使用popToRootViewControllerAnimated方法代替pushViewController

[self.navigationController popToRootViewControllerAnimated:animated];

答案 1 :(得分:0)

您的层次结构似乎不正确。标签栏控制器应该是根视图控制器。对于每个选项卡,您可以拥有一个导航控制器,该控制器具有自己的推送和弹出控制器。也就是说,您的标签栏将始终可见,因为这是您拥有基于标签栏的应用程序时所期望的行为。如果要显示未显示标签栏的视图,则需要将该视图控制器作为模板控制器顶部的模态视图控制器提供。