user2656381
user2656381

Reputation: 145

How to push rootviewcontroller in Ios

I push new StatusViewController(i created UITabbarViewController programmically in it) from rootviewController (UInavigation controller). Now, i want to click on logout button, it push rootviewcontroller but i used below code, it push rootviewcontroller fine but it still tabbar at the bottom.

This code to call rootviewcontroller:

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

And this code is created UItabbarcontroller in StatusViewController:

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

You can see this image : enter image description here

Upvotes: 0

Views: 2273

Answers (2)

Adam Richardson
Adam Richardson

Reputation: 2526

Use popToRootViewControllerAnimated method instead of pushViewController:

[self.navigationController popToRootViewControllerAnimated:animated];

Upvotes: 3

Hetal Vora
Hetal Vora

Reputation: 3361

Your hierarchy does not seem correct. Your tab bar controller should be the root view controller. For each tab, you can have a navigation controller which has its own controllers to push and pop. That said, your tab bar will always be visible since that is the behavior that is expected when you have a tab bar based app. If you want to present a view which does not show a tab bar, you will need to present that view controller as a Modal view controller on top of your tab bar controller.

Upvotes: 0

Related Questions