some_id
some_id

Reputation: 29886

Resetting the rootViewController on a NavigationController

I am using the PKRevealController that gives the side menu functionality to an application.

I Have UIbuttons in the side menu and they trigger a view to be pushed on the navigation stack. However, Each view being pushed has a back button that leads to the navigation view controller.

What would be the correct way to make sure that each view pushed onto the stack will become the root of the navigation stack? Except obviously not view controllers that I need to stack.

Upvotes: 0

Views: 965

Answers (2)

jailani
jailani

Reputation: 2270

You can make it any view controller as the root view controller of the navigation controller for example

You can try this.....Just replace this code in FrontView controller didSelectRowAtindexPath

         //    [tableView deselectRowAtIndexPath:indexPath animated:YES];
         self.navigationController.viewControllers = [NSArray arrayWithObject: [[LeftDemoViewController alloc]init]];

Upvotes: 2

pdrcabrod
pdrcabrod

Reputation: 1477

If you are not going to push view controllers, you may prefer to have a main view, which contains the view of the current view controller. Everytime you change to another app section you remove that view, and insert the view of the new viewcontroller.

But if you prefer to have a navigation stack you can remove the previous viewcontroller from the navigation stack and add the new one. Assuming you will only have one view controller at the same time and you are using a tab bar controller

UIViewController * root = nil;
UINavigationController *rootNavController = [[[UINavigationController alloc]initWithRootViewController:root] autorelease];
[root release];
NSMutableArray * viewControllersArray = [NSMutableArray arrayWithArray:self.tabBar.viewControllers];
[viewControllersArray removeObject:[viewControllersArray lastObject]];
[viewControllersArray addObject:rootNavController];
[self.tabBar setViewControllers:viewControllersArray animated:NO];

If you want to have more than one, instead of removing the last one all the time you will have to remove the first one. So you will have to replace lastObject with objectAtIndex:0 and addObject with insertObject:atIndex:0

Hope it helps

Upvotes: 0

Related Questions